Skip to content

Commit

Permalink
Cosmos DB initialization logic to a new assembly (#3743)
Browse files Browse the repository at this point in the history
* a)Changes done on existing Microsoft.Health.Fhir.CosmosDb Project
1.Icollectionupdater copied to Istoreprocedure in cosmos db old project
2.older Istoreprocedure logic moved to new project with filename IStoredProcedureInstaller
3.StoredProcedureInstaller.cs removed from old db(Microsoft.Health.Fhir.CosmosDb) and moved this logic to new project with filename DataPlaneStoredProcedureInstaller.cs
4.Configs folder contains classes like CosmosDataStoreConfiguration,CosmosCollectionConfiguration moved to Microsoft.Health.Fhir.CosmosDb.Core project
5.Following classes moved to Microsoft.Health.Fhir.CosmosDb.Core project
   -SystemData
   -KnownDocumentProperties
   -ICollectionUpdater
   -CollectionVersion
   -CollectionUpgradeManager
   -IUpgradeManager
   -CollectionInitializer : we have removed depenedancy for RetryExceptionPolicyFactory in constructor
   -ICollectionInitializer
   -CosmosClientExtensions
   -ICosmosDbDistributedLock
   -ICosmosDbDistributedLockFactory
   -ICosmosClientTestProvider

6. Following existing Classes/interfaces modified
   -ICosmosClientInitializer
   -FhirCosmosClientInitializer
   -CosmosDbFhirStorageTestsFixture
          // TODO: TODO: need modify this class to call new CosmosDB .Initialization functions
          // now some existing call are commented
   -CosmosContainerProvider
           // TODO: TODO: need modify this class to call new CosmosDB .Initialization functions
          // now some existing call are commented

b) New Microsoft.Health.Fhir.CosmosDb.Initialization project added
   -Initialization of cosmos DB functionality moved here
   - Moved Storeprocedure installation logic here Added classes like
     DataPlaneStoredProcedureInstaller,StoredProcedureMetadataBase
   - Also we have DataPlaneCollectionSetup class which will implement following methods
       -CreateDatabaseAsync
       - CreateCollection
       -UpdateFhirCollectionSettings

c)Unit Test Project Added Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests project

d)Also Added Microsoft.Health.Fhir.CosmosDb.Core project
  - We have moved common functionalities from Microsoft.Health.Fhir.CosmosDb project

#User Story 112343: [Cosmos][OSS] Move Cosmos DB initialization logic to a new assembly

* versions updated for some packages

* Moved to CosmosDB.Core
 -StoredProcedureBase
 -IStoredProcedure
 -IStoredProcedureMetadata
 -StoredProcedureMetadata

Moved to CosmosDB.Initialization:
 -UpdateUnsupportedSearchParameters
 -FhirCollectionSettingsUpdater

* 1. Added ICollectionDataUpdater interface in cosmosdb project
2.Replaced ICollectionUpdater with ICollectionDataUpdater in CosmosDbSearchParameterStatusInitializer
3.moved else part logic from FhirCollectionSettingsUpdater to CosmosDbSearchParameterStatusInitializer
4.FhirCollectionSettingsUpdater  is removed from solution

* worked on code review comments

* worked on review comments and cleaned up code

* done with end to end flow testing with CosmosDbFhirStorageTestsFixture class

* resolved installed storeprocedure issue

* Unit test cases updated . DataPlaneCosmosDbRegistarionExtensions issue is resolved

* resolved build issue for hardDelete

* identity package updated to latest version to solve vulnerability issue

* Solve the test failures in PR
Disconnect ICollectionSetup from CosmosClient and Container.

* fixed review comments

* solved issues with unit test

* Added new project refrences to docker file

* updated docker file

* removed extra call to fhircollectionsetting updater

* Refactoring to avoid circle dependency (#3877)

* merging refatoring changes with local branch

* solved merge issues

* fixes namespace issue for Core.Resources

* resolves unit test issue for FHIRCosmosClientInitializer

* Resolves unite test issues

* added missing decorators on DataPlaneCollectionSetupTests

* work on review comments

* Adds classification attibutes

* -Adding newly added project references to R4.slnf and R5.slnf
-Adding simple threadsafe logic for creating CosmosClient instance

* refactoring CreateCosmosClient logic to have validation logic

---------

Co-authored-by: Fernando Henrique Inocêncio Borba Ferreira <[email protected]>
  • Loading branch information
mahajan-xor and fhibf authored Jul 4, 2024
1 parent ec9f656 commit 6f07bfc
Show file tree
Hide file tree
Showing 87 changed files with 1,076 additions and 368 deletions.
23 changes: 22 additions & 1 deletion Microsoft.Health.Fhir.sln
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerfTester", "tools\PerfTes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlScriptRunner", "tools\SqlScriptRunner\SqlScriptRunner.csproj", "{76C29222-8D35-43A2-89C5-43114D113C10}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.Fhir.CosmosDb.Initialization", "src\Microsoft.Health.Fhir.CosmosDb.Initialization\Microsoft.Health.Fhir.CosmosDb.Initialization.csproj", "{10661BC9-01B0-4E35-9751-3B5CE97E25C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests", "src\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests.csproj", "{B9AAA11D-8C8C-44C3-AADE-801376EF82F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Health.Fhir.CosmosDb.Core", "src\Microsoft.Health.Fhir.CosmosDb.Core\Microsoft.Health.Fhir.CosmosDb.Core.csproj", "{1CD46DC5-6022-4BBE-9A1C-6B13C3CEFC75}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -465,6 +471,18 @@ Global
{76C29222-8D35-43A2-89C5-43114D113C10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76C29222-8D35-43A2-89C5-43114D113C10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76C29222-8D35-43A2-89C5-43114D113C10}.Release|Any CPU.Build.0 = Release|Any CPU
{10661BC9-01B0-4E35-9751-3B5CE97E25C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10661BC9-01B0-4E35-9751-3B5CE97E25C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10661BC9-01B0-4E35-9751-3B5CE97E25C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10661BC9-01B0-4E35-9751-3B5CE97E25C0}.Release|Any CPU.Build.0 = Release|Any CPU
{B9AAA11D-8C8C-44C3-AADE-801376EF82F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9AAA11D-8C8C-44C3-AADE-801376EF82F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9AAA11D-8C8C-44C3-AADE-801376EF82F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9AAA11D-8C8C-44C3-AADE-801376EF82F0}.Release|Any CPU.Build.0 = Release|Any CPU
{1CD46DC5-6022-4BBE-9A1C-6B13C3CEFC75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1CD46DC5-6022-4BBE-9A1C-6B13C3CEFC75}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1CD46DC5-6022-4BBE-9A1C-6B13C3CEFC75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1CD46DC5-6022-4BBE-9A1C-6B13C3CEFC75}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -557,10 +575,13 @@ Global
{71A1A274-23A9-441B-BB47-1FC561FF0F35} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{5E0B69FE-40DE-42E8-9F67-4BB7410AF67C} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{76C29222-8D35-43A2-89C5-43114D113C10} = {B70945F4-01A6-4351-955B-C4A2943B5E3B}
{10661BC9-01B0-4E35-9751-3B5CE97E25C0} = {DC5A2CB1-8995-4D39-97FE-3CE80E892C69}
{B9AAA11D-8C8C-44C3-AADE-801376EF82F0} = {DC5A2CB1-8995-4D39-97FE-3CE80E892C69}
{1CD46DC5-6022-4BBE-9A1C-6B13C3CEFC75} = {DC5A2CB1-8995-4D39-97FE-3CE80E892C69}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E370FB31-CF95-47D1-B1E1-863A77973FF8}
RESX_SortFileContentOnSave = True
SolutionGuid = {E370FB31-CF95-47D1-B1E1-863A77973FF8}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
test\Microsoft.Health.Fhir.Shared.Tests.E2E.Common\Microsoft.Health.Fhir.Shared.Tests.E2E.Common.projitems*{0478b687-7105-40f6-a2dc-81057890e944}*SharedItemsImports = 13
Expand Down
3 changes: 3 additions & 0 deletions R4.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"src\\Microsoft.Health.Fhir.Azure\\Microsoft.Health.Fhir.Azure.csproj",
"src\\Microsoft.Health.Fhir.Core.UnitTests\\Microsoft.Health.Fhir.Core.UnitTests.csproj",
"src\\Microsoft.Health.Fhir.Core\\Microsoft.Health.Fhir.Core.csproj",
"src\Microsoft.Health.Fhir.CosmosDb.Core\Microsoft.Health.Fhir.CosmosDb.Core.csproj",
"src\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests.csproj",
"src\Microsoft.Health.Fhir.CosmosDb.Initialization\Microsoft.Health.Fhir.CosmosDb.Initialization.csproj",
"src\\Microsoft.Health.Fhir.CosmosDb.UnitTests\\Microsoft.Health.Fhir.CosmosDb.UnitTests.csproj",
"src\\Microsoft.Health.Fhir.CosmosDb\\Microsoft.Health.Fhir.CosmosDb.csproj",
"src\\Microsoft.Health.Fhir.R4.Api\\Microsoft.Health.Fhir.R4.Api.csproj",
Expand Down
3 changes: 3 additions & 0 deletions R5.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"src\\Microsoft.Health.Fhir.Azure\\Microsoft.Health.Fhir.Azure.csproj",
"src\\Microsoft.Health.Fhir.Core.UnitTests\\Microsoft.Health.Fhir.Core.UnitTests.csproj",
"src\\Microsoft.Health.Fhir.Core\\Microsoft.Health.Fhir.Core.csproj",
"src\Microsoft.Health.Fhir.CosmosDb.Core\Microsoft.Health.Fhir.CosmosDb.Core.csproj",
"src\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests\Microsoft.Health.Fhir.CosmosDb.Initialization.UnitTests.csproj",
"src\Microsoft.Health.Fhir.CosmosDb.Initialization\Microsoft.Health.Fhir.CosmosDb.Initialization.csproj",
"src\\Microsoft.Health.Fhir.CosmosDb.UnitTests\\Microsoft.Health.Fhir.CosmosDb.UnitTests.csproj",
"src\\Microsoft.Health.Fhir.CosmosDb\\Microsoft.Health.Fhir.CosmosDb.csproj",
"src\\Microsoft.Health.Fhir.R5.Api\\Microsoft.Health.Fhir.R5.Api.csproj",
Expand Down
6 changes: 6 additions & 0 deletions build/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ COPY ./src/Microsoft.Health.Fhir.Api/Microsoft.Health.Fhir.Api.csproj \
COPY ./src/Microsoft.Health.Fhir.CosmosDb/Microsoft.Health.Fhir.CosmosDb.csproj \
./src/Microsoft.Health.Fhir.CosmosDb/Microsoft.Health.Fhir.CosmosDb.csproj

COPY ./src/Microsoft.Health.Fhir.CosmosDb.Core/Microsoft.Health.Fhir.CosmosDb.Core.csproj \
./src/Microsoft.Health.Fhir.CosmosDb.Core/Microsoft.Health.Fhir.CosmosDb.Core.csproj

COPY ./src/Microsoft.Health.Fhir.CosmosDb.Initialization/Microsoft.Health.Fhir.CosmosDb.Initialization.csproj \
./src/Microsoft.Health.Fhir.CosmosDb.Initialization/Microsoft.Health.Fhir.CosmosDb.Initialization.csproj

COPY ./src/Microsoft.Health.Fhir.${FHIR_VERSION}.Core/Microsoft.Health.Fhir.${FHIR_VERSION}.Core.csproj \
./src/Microsoft.Health.Fhir.${FHIR_VERSION}.Core/Microsoft.Health.Fhir.${FHIR_VERSION}.Core.csproj

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

namespace Microsoft.Health.Fhir.CosmosDb.Configs
namespace Microsoft.Health.Fhir.CosmosDb.Core.Configs
{
public class CosmosCollectionConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Collections.Generic;
using Microsoft.Azure.Cosmos;

namespace Microsoft.Health.Fhir.CosmosDb.Configs
namespace Microsoft.Health.Fhir.CosmosDb.Core.Configs
{
public class CosmosDataStoreConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using System;

namespace Microsoft.Health.Fhir.CosmosDb.Configs
namespace Microsoft.Health.Fhir.CosmosDb.Core.Configs
{
public class CosmosDataStoreParallelQueryOptions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

namespace Microsoft.Health.Fhir.CosmosDb.Configs
namespace Microsoft.Health.Fhir.CosmosDb.Core.Configs
{
public class CosmosDataStoreRetryOptions
{
Expand Down
13 changes: 13 additions & 0 deletions src/Microsoft.Health.Fhir.CosmosDb.Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

namespace Microsoft.Health.Fhir.CosmosDb.Core
{
public static class Constants
{
public const string CollectionConfigurationName = "fhirCosmosDb";
public const string RawResource = "rawResource";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public static class CosmosClientExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage.Versioning
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public interface ICollectionUpdater
public interface ICollectionDataUpdater
{
Task ExecuteAsync(Container container, CancellationToken cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
using Polly;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public interface ICollectionInitializer
{
Task<Container> InitializeCollectionAsync(CosmosClient client, CancellationToken cancellationToken = default);
Task<Container> InitializeCollectionAsync(CosmosClient client, AsyncPolicy retryPolicy, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Polly;

namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public interface ICollectionSetup
{
public Task CreateDatabaseAsync(AsyncPolicy retryPolicy, CancellationToken cancellationToken);

public Task CreateCollectionAsync(IEnumerable<ICollectionInitializer> collectionInitializers, AsyncPolicy retryPolicy, CancellationToken cancellationToken = default);

public Task UpdateFhirCollectionSettingsAsync(CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
using Microsoft.Health.Fhir.CosmosDb.Configs;
using Microsoft.Health.Fhir.CosmosDb.Core.Configs;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
/// <summary>
/// Provides methods for creating a CosmosClient instance and initializing a collection.
Expand All @@ -32,16 +32,6 @@ public interface ICosmosClientInitializer
/// <param name="cosmosCollectionConfiguration">The collection configuration for the query to use</param>
Task OpenCosmosClient(CosmosClient client, CosmosDataStoreConfiguration configuration, CosmosCollectionConfiguration cosmosCollectionConfiguration);

/// <summary>
/// Ensures that the necessary database and collection exist with the proper indexing policy and stored procedures
/// </summary>
/// <param name="client">The <see cref="CosmosClient"/> instance to use for initialization.</param>
/// <param name="cosmosDataStoreConfiguration">The data store configuration.</param>
/// <param name="collectionInitializers">The collection of collection initializers.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task</returns>
Task InitializeDataStoreAsync(CosmosClient client, CosmosDataStoreConfiguration cosmosDataStoreConfiguration, IEnumerable<ICollectionInitializer> collectionInitializers, CancellationToken cancellationToken = default);

/// <summary>
/// Creates a new Container instance for access the Cosmos API
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
using Microsoft.Health.Fhir.CosmosDb.Configs;
using Microsoft.Health.Fhir.CosmosDb.Core.Configs;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public interface ICosmosClientTestProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public interface ICosmosDbDistributedLock : IAsyncDisposable, IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using Microsoft.Azure.Cosmos;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public interface ICosmosDbDistributedLockFactory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage
{
public static class KnownDocumentProperties
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Scripts;

namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage.StoredProcedures
{
public interface IStoredProcedure
{
Task<StoredProcedureExecuteResponse<T>> ExecuteStoredProcAsync<T>(Scripts client, string partitionId, CancellationToken cancellationToken, params object[] parameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;

namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage.StoredProcedures
{
public interface IStoredProcedureInstaller
{
Task ExecuteAsync(Container container, CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

using Microsoft.Azure.Cosmos.Scripts;

namespace Microsoft.Health.Fhir.CosmosDb.Features.Storage.StoredProcedures
namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage.StoredProcedures
{
public interface IStoredProcedure
public interface IStoredProcedureMetadata
{
string FullName { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System;
using System.Threading;
using System.Threading.Tasks;
using EnsureThat;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Scripts;
using Microsoft.Health.Core.Extensions;

namespace Microsoft.Health.Fhir.CosmosDb.Core.Features.Storage.StoredProcedures
{
public abstract class StoredProcedureBase : IStoredProcedure
{
private readonly IStoredProcedureMetadata _storedProcedureMetadata;

protected StoredProcedureBase(IStoredProcedureMetadata storedProcedureMetadata)
{
EnsureArg.IsNotNull(storedProcedureMetadata, nameof(storedProcedureMetadata));

_storedProcedureMetadata = storedProcedureMetadata;
}

public string FullName => _storedProcedureMetadata.FullName;

public async Task<StoredProcedureExecuteResponse<T>> ExecuteStoredProcAsync<T>(Scripts client, string partitionId, CancellationToken cancellationToken, params object[] parameters)
{
EnsureArg.IsNotNull(client, nameof(client));
EnsureArg.IsNotNull(partitionId, nameof(partitionId));

StoredProcedureExecuteResponse<T> results = await client.ExecuteStoredProcedureAsync<T>(
FullName,
new PartitionKey(partitionId),
parameters,
cancellationToken: cancellationToken);

return results;
}
}
}
Loading

0 comments on commit 6f07bfc

Please sign in to comment.