Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions eng/pipelines/templates/jobs/pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
inputs:
pwsh: true
filePath: $(Build.SourcesDirectory)/eng/scripts/Test-Semver.ps1
arguments: -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo'
arguments: -PackageInfoDirectory '$(Build.ArtifactStagingDirectory)/PackageInfo' -Toolchain '1.92'

- task: Powershell@2
displayName: Pack Crates
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
inputs:
pwsh: true
filePath: $(Build.SourcesDirectory)/eng/scripts/Test-Semver.ps1
arguments: -PackageNames $(PackageNames)
arguments: -PackageNames $(PackageNames) -Toolchain '1.92'

- task: Powershell@2
displayName: Pack Crates
Expand All @@ -151,4 +151,4 @@ jobs:
parameters:
Artifacts: ${{ parameters.Artifacts }}

- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
- template: /eng/common/pipelines/templates/steps/detect-api-changes.yml
73 changes: 42 additions & 31 deletions sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,34 @@ use crate::{
clients::{offers_client, ClientContext},
feed_range::FeedRange,
models::{
BatchResponse, ContainerProperties, CosmosResponse, ItemResponse, ResourceResponse,
ThroughputProperties,
BatchResponse, ContainerProperties, ItemResponse, ResourceResponse, ThroughputProperties,
},
options::{
BatchOptions, Precondition, QueryOptions, ReadContainerOptions, ReadFeedRangesOptions,
SessionToken,
},
resource_context::{ResourceLink, ResourceType},
resource_context::ResourceLink,
transactional_batch::TransactionalBatch,
DeleteContainerOptions, FeedItemIterator, ItemReadOptions, ItemWriteOptions, PartitionKey,
Query, ReplaceContainerOptions, ThroughputOptions,
};
use std::sync::Arc;

use super::ThroughputPoller;
use crate::cosmos_request::CosmosRequest;
use crate::handler::container_connection::ContainerConnection;
use crate::operation_context::OperationType;
use crate::routing::partition_key_range_cache::PartitionKeyRangeCache;
use azure_core::http::Context;
use azure_data_cosmos_driver::models::{
effective_partition_key::EffectivePartitionKey as DriverEpk, ContainerReference,
CosmosOperation, ItemReference, PartitionKeyKind,
};
use azure_data_cosmos_driver::options::OperationOptions;
use serde::{de::DeserializeOwned, Serialize};

/// A client for working with a specific container in a Cosmos DB account.
///
/// You can get a `Container` by calling [`DatabaseClient::container_client()`](crate::clients::DatabaseClient::container_client()).
#[derive(Clone)]
pub struct ContainerClient {
link: ResourceLink,
container_connection: Arc<ContainerConnection>,
container_ref: ContainerReference,
context: ClientContext,
Expand All @@ -49,10 +45,6 @@ impl ContainerClient {
container_id: &str,
database_id: &str,
) -> azure_core::Result<Self> {
let link = database_link
.feed(ResourceType::Containers)
.item(container_id);

// Eagerly resolve immutable container metadata from the driver.
let container_ref = context
.driver
Expand All @@ -77,7 +69,6 @@ impl ContainerClient {
));

Ok(Self {
link,
container_connection,
container_ref,
context,
Expand Down Expand Up @@ -108,14 +99,17 @@ impl ContainerClient {
)]
options: Option<ReadContainerOptions>,
) -> azure_core::Result<ResourceResponse<ContainerProperties>> {
let cosmos_request =
CosmosRequest::builder(OperationType::Read, self.link.clone()).build()?;
let response: CosmosResponse<ContainerProperties> = self
.container_connection
.send(cosmos_request, Context::default())
let operation = CosmosOperation::read_container(self.container_ref.clone());
Comment thread
simorenoh marked this conversation as resolved.

let driver_response = self
.context
.driver
.execute_operation(operation, OperationOptions::default())
.await?;

Ok(ResourceResponse::new(response))
Ok(ResourceResponse::new(
crate::driver_bridge::driver_response_to_cosmos_response(driver_response),
))
}

/// Updates the indexing policy of the container.
Expand Down Expand Up @@ -151,13 +145,25 @@ impl ContainerClient {
)]
options: Option<ReplaceContainerOptions>,
) -> azure_core::Result<ResourceResponse<ContainerProperties>> {
let cosmos_request = CosmosRequest::builder(OperationType::Replace, self.link.clone())
.json(&properties)
.build()?;
self.container_connection
.send(cosmos_request, Context::default())
.await
.map(ResourceResponse::new)
let body = serde_json::to_vec(&properties)?;
let operation =
CosmosOperation::replace_container(self.container_ref.clone()).with_body(body);

// Control-plane replaces always need the full response body so the
// caller can inspect the updated resource properties.
let mut operation_options = OperationOptions::default();
operation_options.content_response_on_write =
Some(azure_data_cosmos_driver::options::ContentResponseOnWrite::Enabled);

let driver_response = self
.context
.driver
.execute_operation(operation, operation_options)
.await?;

Ok(ResourceResponse::new(
crate::driver_bridge::driver_response_to_cosmos_response(driver_response),
))
}

/// Reads container throughput properties, if any.
Expand Down Expand Up @@ -239,12 +245,17 @@ impl ContainerClient {
)]
options: Option<DeleteContainerOptions>,
) -> azure_core::Result<ResourceResponse<()>> {
let cosmos_request =
CosmosRequest::builder(OperationType::Delete, self.link.clone()).build()?;
self.container_connection
.send(cosmos_request, Context::default())
.await
.map(ResourceResponse::new)
let operation = CosmosOperation::delete_container(self.container_ref.clone());

let driver_response = self
.context
.driver
.execute_operation(operation, OperationOptions::default())
.await?;

Ok(ResourceResponse::new(
crate::driver_bridge::driver_response_to_cosmos_response(driver_response),
))
}

/// Creates a new item in the container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ impl CosmosOperation {
Self::new(OperationType::Delete, resource_ref)
}

/// Replaces a container's properties.
///
/// Use `with_body()` to provide the updated container properties JSON.
pub fn replace_container(container: ContainerReference) -> Self {
let resource_ref: CosmosResourceReference = container.into();
Self::new(OperationType::Replace, resource_ref)
Comment thread
simorenoh marked this conversation as resolved.
}

/// Reads a container's properties from the service.
///
/// Returns the full container properties payload for the container,
Expand Down