Skip to content

Commit

Permalink
[Bundle] Simplify profile refresh during bundle execution (#4715)
Browse files Browse the repository at this point in the history
* Changes to support profiles not being updates during bundle executions.

* Adding profile refresh to bundle handler.

* Adding new tests to validate if profile changes result in calls to profile refresh.
  • Loading branch information
fhibf authored Nov 8, 2024
1 parent 6525a6d commit 311dade
Show file tree
Hide file tree
Showing 28 changed files with 364 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public sealed class BundleOrchestratorNamingConventions
{
public const string HttpHeaderBundleProcessingLogic = "x-bundle-processing-logic";

public const string HttpHeaderOperationTag = "x-bundle-operation-id";
public const string HttpInnerBundleRequestProcessingLogic = "x-bundle-innerrequest-processing-logic";

public const string HttpHeaderBundleResourceHttpVerb = "x-bundle-resource-http-verb";
public const string HttpInnerBundleRequestHeaderOperationTag = "x-bundle-innerrequest-operation-id";

public const string HttpInnerBundleRequestHeaderBundleResourceHttpVerb = "x-bundle-innerrequest-resource-http-verb";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Messages.Bundle
{
public interface IBundleInnerRequest
{
BundleResourceContext BundleResourceContext { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using EnsureThat;
using MediatR;
using Microsoft.Health.Fhir.Core.Features.Conformance;
using Microsoft.Health.Fhir.Core.Messages.Bundle;
using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Messages
{
public abstract class ConditionalResourceRequest<TResponse> : IRequireCapability, IRequest<TResponse>
public abstract class ConditionalResourceRequest<TResponse> : IRequireCapability, IRequest<TResponse>, IBundleInnerRequest
{
protected ConditionalResourceRequest(string resourceType, IReadOnlyList<Tuple<string, string>> conditionalParameters, BundleResourceContext bundleResourceContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
using EnsureThat;
using MediatR;
using Microsoft.Health.Fhir.Core.Features.Conformance;
using Microsoft.Health.Fhir.Core.Messages.Bundle;
using Microsoft.Health.Fhir.Core.Messages.Upsert;
using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Messages.Create
{
public class CreateResourceRequest : IRequest<UpsertResourceResponse>, IRequest, IRequireCapability
public class CreateResourceRequest : IRequest<UpsertResourceResponse>, IRequest, IRequireCapability, IBundleInnerRequest
{
public CreateResourceRequest(ResourceElement resource, BundleResourceContext bundleResourceContext = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using MediatR;
using Microsoft.Health.Fhir.Core.Features.Conformance;
using Microsoft.Health.Fhir.Core.Features.Persistence;
using Microsoft.Health.Fhir.Core.Messages.Bundle;
using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Messages.Delete
{
public class DeleteResourceRequest : IRequest<DeleteResourceResponse>, IRequireCapability
public class DeleteResourceRequest : IRequest<DeleteResourceResponse>, IRequireCapability, IBundleInnerRequest
{
public DeleteResourceRequest(ResourceKey resourceKey, DeleteOperation deleteOperation, BundleResourceContext bundleResourceContext = null, bool allowPartialSuccess = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using MediatR;
using Microsoft.Health.Fhir.Core.Features.Conformance;
using Microsoft.Health.Fhir.Core.Features.Persistence;
using Microsoft.Health.Fhir.Core.Messages.Bundle;
using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Messages.Get
{
public class GetResourceRequest : IRequest<GetResourceResponse>, IRequireCapability
public class GetResourceRequest : IRequest<GetResourceResponse>, IRequireCapability, IBundleInnerRequest
{
public GetResourceRequest(ResourceKey resourceKey, BundleResourceContext bundleResourceContext = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
using Microsoft.Health.Fhir.Core.Features.Conformance;
using Microsoft.Health.Fhir.Core.Features.Persistence;
using Microsoft.Health.Fhir.Core.Features.Resources.Patch;
using Microsoft.Health.Fhir.Core.Messages.Bundle;
using Microsoft.Health.Fhir.Core.Messages.Upsert;
using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Messages.Patch
{
public sealed class PatchResourceRequest : IRequest<UpsertResourceResponse>, IRequireCapability
public sealed class PatchResourceRequest : IRequest<UpsertResourceResponse>, IRequireCapability, IBundleInnerRequest
{
public PatchResourceRequest(ResourceKey resourceKey, PatchPayload payload, BundleResourceContext bundleResourceContext, WeakETag weakETag = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
using MediatR;
using Microsoft.Health.Fhir.Core.Features.Conformance;
using Microsoft.Health.Fhir.Core.Features.Persistence;
using Microsoft.Health.Fhir.Core.Messages.Bundle;
using Microsoft.Health.Fhir.Core.Models;

namespace Microsoft.Health.Fhir.Core.Messages.Upsert
{
public class UpsertResourceRequest : IRequest<UpsertResourceResponse>, IRequest, IRequireCapability
public class UpsertResourceRequest : IRequest<UpsertResourceResponse>, IRequest, IRequireCapability, IBundleInnerRequest
{
public UpsertResourceRequest(ResourceElement resource, BundleResourceContext bundleResourceContext = null, WeakETag weakETag = null)
{
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.Api.Features.Resources.Bundle
namespace Microsoft.Health.Fhir.Core.Models
{
public enum BundleProcessingLogic
{
Expand Down
10 changes: 9 additions & 1 deletion src/Microsoft.Health.Fhir.Core/Models/BundleResourceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ namespace Microsoft.Health.Fhir.Core.Models
{
public sealed class BundleResourceContext
{
public BundleResourceContext(HTTPVerb httpVerb, Guid bundleOperationId)
public BundleResourceContext(BundleProcessingLogic processingLogic, HTTPVerb httpVerb, Guid bundleOperationId)
{
ProcessingLogic = processingLogic;
HttpVerb = httpVerb;
BundleOperationId = bundleOperationId;
}

public BundleProcessingLogic ProcessingLogic { get; }

public HTTPVerb HttpVerb { get; }

public Guid BundleOperationId { get; }

public bool IsParallelBundle
{
get { return ProcessingLogic == BundleProcessingLogic.Parallel; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using EnsureThat;
Expand Down Expand Up @@ -190,12 +189,12 @@ await Parallel.ForEachAsync(resources, parallelOptions, async (resource, innerCt
try
{
UpsertOutcome upsertOutcome = await InternalUpsertAsync(
resource.Wrapper,
resource.WeakETag,
resource.AllowCreate,
resource.KeepHistory,
innerCt,
resource.RequireETagOnUpdate);
resource.Wrapper,
resource.WeakETag,
resource.AllowCreate,
resource.KeepHistory,
innerCt,
resource.RequireETagOnUpdate);
var result = new DataStoreOperationOutcome(upsertOutcome);
results.AddOrUpdate(identifier, _ => result, (_, _) => result);
Expand All @@ -220,9 +219,12 @@ await Parallel.ForEachAsync(resources, parallelOptions, async (resource, innerCt

public async Task<UpsertOutcome> UpsertAsync(ResourceWrapperOperation resource, CancellationToken cancellationToken)
{
bool isBundleOperation = _bundleOrchestrator.IsEnabled && resource.BundleResourceContext != null;
bool isBundleParallelOperation =
_bundleOrchestrator.IsEnabled &&
resource.BundleResourceContext != null &&
resource.BundleResourceContext.IsParallelBundle;

if (isBundleOperation)
if (isBundleParallelOperation)
{
IBundleOrchestratorOperation operation = _bundleOrchestrator.GetOperation(resource.BundleResourceContext.BundleOperationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Health.Fhir.Api.Features.Headers;
using Microsoft.Health.Fhir.Api.Features.Resources;
using Microsoft.Health.Fhir.Api.Features.Resources.Bundle;
using Microsoft.Health.Fhir.Core.Features;
using Microsoft.Health.Fhir.Core.Features.Context;
using Microsoft.Health.Fhir.Core.Features.Persistence.Orchestration;
using Microsoft.Health.Fhir.Core.Models;
using Microsoft.Health.Fhir.Tests.Common;
using Microsoft.Health.Test.Utilities;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using Azure;
using Hl7.Fhir.Model;
using Hl7.Fhir.Serialization;
using Hl7.Fhir.Specification.Navigation;
using Hl7.FhirPath.Sprache;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.AspNetCore.Routing;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
Expand All @@ -30,30 +19,22 @@
using Microsoft.Health.Api.Features.Audit;
using Microsoft.Health.Core.Features.Context;
using Microsoft.Health.Fhir.Api.Features.Bundle;
using Microsoft.Health.Fhir.Api.Features.Exceptions;
using Microsoft.Health.Fhir.Api.Features.Resources.Bundle;
using Microsoft.Health.Fhir.Api.Features.Routing;
using Microsoft.Health.Fhir.Core.Configs;
using Microsoft.Health.Fhir.Core.Exceptions;
using Microsoft.Health.Fhir.Core.Extensions;
using Microsoft.Health.Fhir.Core.Features;
using Microsoft.Health.Fhir.Core.Features.Context;
using Microsoft.Health.Fhir.Core.Features.Persistence;
using Microsoft.Health.Fhir.Core.Features.Persistence.Orchestration;
using Microsoft.Health.Fhir.Core.Features.Resources;
using Microsoft.Health.Fhir.Core.Features.Resources.Bundle;
using Microsoft.Health.Fhir.Core.Features.Search;
using Microsoft.Health.Fhir.Core.Features.Security.Authorization;
using Microsoft.Health.Fhir.Core.Messages.Bundle;
using Microsoft.Health.Fhir.Core.Features.Validation;
using Microsoft.Health.Fhir.Core.UnitTests.Features.Context;
using Microsoft.Health.Fhir.Tests.Common;
using Microsoft.Health.Fhir.ValueSets;
using Microsoft.Health.Test.Utilities;
using NSubstitute;
using NSubstitute.Core;
using Xunit;
using static Hl7.Fhir.Model.Bundle;
using Task = System.Threading.Tasks.Task;

namespace Microsoft.Health.Fhir.Api.UnitTests.Features.Resources.Bundle
{
Expand Down Expand Up @@ -161,6 +142,8 @@ private IFhirRequestContext CreateRequestContextForBundleHandlerProcessing(Bundl

IAuditEventTypeMapping auditEventTypeMapping = Substitute.For<IAuditEventTypeMapping>();

IProvideProfilesForValidation profilesResolver = Substitute.For<IProvideProfilesForValidation>();

var mediator = Substitute.For<IMediator>();

var bundleHandler = new BundleHandler(
Expand All @@ -179,6 +162,7 @@ private IFhirRequestContext CreateRequestContextForBundleHandlerProcessing(Bundl
DisabledFhirAuthorizationService.Instance,
mediator,
router,
profilesResolver,
NullLogger<BundleHandler>.Instance);

return fhirRequestContextAccessor.RequestContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Threading.Tasks;
using Microsoft.Health.Fhir.Api.Features.Resources.Bundle;
using Microsoft.Health.Fhir.Core.Models;
using Microsoft.Health.Fhir.Tests.Common;
using Microsoft.Health.Test.Utilities;
using Newtonsoft.Json.Linq;
Expand Down
Loading

0 comments on commit 311dade

Please sign in to comment.