Skip to content

Commit b43db5f

Browse files
Revert the 'instantiates' field change (#5436)
* Revert "Populating 'instantiates' field of CapabilityStatement. (#5241)" This reverts commit ba6f9fb. * Removing E2E for instantiates field.
1 parent 3879ee4 commit b43db5f

File tree

13 files changed

+36
-658
lines changed

13 files changed

+36
-658
lines changed

src/Microsoft.Health.Fhir.Core/Features/Conformance/IVolatileProvideCapability.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/Microsoft.Health.Fhir.Core/Features/Conformance/Models/ListedCapabilityStatement.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,5 @@ public ListedCapabilityStatement()
6262
public IDictionary<string, JToken> AdditionalData { get; }
6363

6464
public ICollection<ReferenceComponent> Profile { get; }
65-
66-
public ICollection<string> Instantiates { get; internal set; }
6765
}
6866
}

src/Microsoft.Health.Fhir.Core/Features/Conformance/SystemConformanceProvider.cs

Lines changed: 36 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -246,23 +246,28 @@ public async Task BackgroudLoop()
246246
// If the sync profile is requested or the rebuild interval has elapsed, then we will rebuild the capability statement and update in-memory metadata.
247247
if (_builder != null)
248248
{
249-
var cancellationToken = _cancellationTokenSource.Token;
250-
251249
// Update search params.
252250
_builder.SyncSearchParameters();
253251

254252
// Update supported profiles.
255-
await _builder.SyncProfilesAsync(cancellationToken);
256-
257-
// Update other fields populated by providers.
258-
await UpdateMetadataAsync(cancellationToken);
253+
await _builder.SyncProfilesAsync(_cancellationTokenSource.Token);
259254
}
260255
}
261256
catch (Exception e)
262257
{
263258
// Do not let exceptions escape the background loop.
264259
_logger.LogError(e, "SystemConformanceProvider: Unexpected error during background capability statement rebuild.");
265260
}
261+
262+
await (_metadataSemaphore?.WaitAsync(_cancellationTokenSource.Token) ?? Task.CompletedTask);
263+
try
264+
{
265+
_metadata = null;
266+
}
267+
finally
268+
{
269+
_metadataSemaphore?.Release();
270+
}
266271
}
267272
}
268273

@@ -346,6 +351,16 @@ public async Task Handle(RebuildCapabilityStatement notification, CancellationTo
346351
break;
347352
}
348353
}
354+
355+
await (_metadataSemaphore?.WaitAsync(cancellationToken) ?? Task.CompletedTask);
356+
try
357+
{
358+
_metadata = null;
359+
}
360+
finally
361+
{
362+
_metadataSemaphore?.Release();
363+
}
349364
}
350365

351366
public override async Task<ResourceElement> GetMetadata(CancellationToken cancellationToken = default)
@@ -356,16 +371,27 @@ public override async Task<ResourceElement> GetMetadata(CancellationToken cancel
356371
}
357372

358373
// There is a chance that the BackgroundLoop handler sets _metadata to null between when it is checked and returned, so the value is stored in a local variable.
359-
ResourceElement metadata = await UpdateMetadataAsync(cancellationToken);
360-
if (metadata == null)
374+
ResourceElement metadata;
375+
if ((metadata = _metadata) != null)
361376
{
362-
metadata = await GetCapabilityStatementOnStartup(cancellationToken);
377+
return metadata;
363378
}
364379

380+
_ = await GetCapabilityStatementOnStartup(cancellationToken);
381+
365382
// The semaphore is only used for building the metadata because claiming it before the GetCapabilityStatementOnStartup was leading to deadlocks where the creation
366383
// of metadata could trigger a rebuild. The rebuild handler had to wait on the metadata semaphore, which wouldn't be released until the metadata could be built.
367384
// But the metadata builder was waiting on the rebuild handler.
368-
return await SetMetadataAsync(metadata);
385+
await (_metadataSemaphore?.WaitAsync(cancellationToken) ?? Task.CompletedTask);
386+
try
387+
{
388+
_metadata = _builder.Build().ToResourceElement();
389+
return _metadata;
390+
}
391+
finally
392+
{
393+
_metadataSemaphore?.Release();
394+
}
369395
}
370396

371397
private void LogVersioningPolicyConfiguration()
@@ -383,69 +409,5 @@ private void LogVersioningPolicyConfiguration()
383409
_logger.LogInformation(versioning.ToString());
384410
}
385411
}
386-
387-
private async Task<ResourceElement> UpdateMetadataAsync(CancellationToken cancellationToken)
388-
{
389-
await (_metadataSemaphore?.WaitAsync(_cancellationTokenSource.Token) ?? Task.CompletedTask);
390-
try
391-
{
392-
// Note: the method will update non-static sections of the metadata only; thus, it does nothing
393-
// when the full metadata is not yet built.
394-
if (_builder != null && _metadata != null)
395-
{
396-
_logger.LogInformation("SystemConformanceProvider: Updating the metadata.");
397-
398-
using (IScoped<IEnumerable<IProvideCapability>> providerFactory = _capabilityProviders())
399-
{
400-
var providers = providerFactory.Value?
401-
.Where(x => x is IVolatileProvideCapability)?
402-
.Select(x => (IVolatileProvideCapability)x)
403-
.ToList()
404-
?? new List<IVolatileProvideCapability>();
405-
foreach (var provider in providers)
406-
{
407-
Stopwatch watch = Stopwatch.StartNew();
408-
409-
try
410-
{
411-
_logger.LogInformation("SystemConformanceProvider: Updating the metadata with '{ProviderName}'.", provider.ToString());
412-
await provider.UpdateAsync(_builder, cancellationToken);
413-
}
414-
catch (Exception e)
415-
{
416-
_logger.LogWarning(e, "Failed to update Capability Statement.");
417-
throw;
418-
}
419-
finally
420-
{
421-
_logger.LogInformation("SystemConformanceProvider: Updating the metadata with '{ProviderName}' completed. Elapsed time {ElapsedTime}.", provider.ToString(), watch.Elapsed);
422-
}
423-
}
424-
}
425-
426-
_metadata = _builder.Build().ToResourceElement();
427-
}
428-
429-
return _metadata;
430-
}
431-
finally
432-
{
433-
_metadataSemaphore?.Release();
434-
}
435-
}
436-
437-
private async Task<ResourceElement> SetMetadataAsync(ResourceElement metadata)
438-
{
439-
await (_metadataSemaphore?.WaitAsync(_cancellationTokenSource.Token) ?? Task.CompletedTask);
440-
try
441-
{
442-
_metadata = metadata;
443-
return _metadata;
444-
}
445-
finally
446-
{
447-
_metadataSemaphore?.Release();
448-
}
449-
}
450412
}
451413
}

src/Microsoft.Health.Fhir.Shared.Api/Modules/FhirModule.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,6 @@ ResourceElement SetMetadata(Resource resource, string versionId, DateTimeOffset
211211
services.AddTransient(typeof(IScopeProvider<>), typeof(ScopeProvider<>));
212212

213213
services.AddScoped<IDocRefRequestConverter, DocRefRequestConverter>();
214-
215-
services.TypesInSameAssembly(KnownAssemblies.All)
216-
.AssignableTo<IInstantiateCapability>()
217-
.Transient()
218-
.AsService<IInstantiateCapability>();
219-
services.AddFactory<IScoped<IEnumerable<IInstantiateCapability>>>();
220214
}
221215
}
222216
}

src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Conformance/InstantiatesCapabilityProviderTests.cs

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)