-
Notifications
You must be signed in to change notification settings - Fork 1
LEGLINK-697: Create Separate DMRP C# Project & Module Structure #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d5b0c3e
Create/scaffold DMRP service
smailliwcs 09767f8
Add DMRP health check to UI
smailliwcs 2808bfd
Merge branch 'dev' into user/steven.williams/LEGLINK-697
smailliwcs e9b4657
Add TODOs for entity mapping
smailliwcs f697409
Rethrow `OperationCanceledException`
smailliwcs 7e5ef62
Sanitize user-provided values
smailliwcs aff5e6a
Add range check for page size
smailliwcs 1568517
Fix typos
smailliwcs f439adf
Return paged responses for search
smailliwcs a41eeb0
Add unit tests
smailliwcs eb99358
Merge branch 'dev' into user/steven.williams/LEGLINK-697
smailliwcs 5507a0e
Configure DMRP service URLs
smailliwcs d0f9fb9
Merge branch 'dev' into user/steven.williams/LEGLINK-697
smailliwcs e35d748
Convert DMRP to class library
smailliwcs 518536e
Tweak routes to match ADR
smailliwcs f6aa2b6
Merge branch 'dev' into user/steven.williams/LEGLINK-697
smailliwcs 298f94a
Remove explicit null-body checks
smailliwcs 680972a
Use `AddDmrpModule` directly in test fixture
smailliwcs af34db9
Log at startup whether DMRP is enabled
smailliwcs 8866ac1
Revert whitespace-only change
smailliwcs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| resources: | ||
| pipelines: | ||
| - pipeline: pipeline-trigger | ||
| source: Build_And_Push_All | ||
| trigger: true | ||
|
|
||
| trigger: | ||
| branches: | ||
| include: | ||
| - dev | ||
| - release/* | ||
| - linkathon/* | ||
| paths: | ||
| include: | ||
| - DotNet/DMRP/* | ||
| - DotNet/Shared/* | ||
| exclude: | ||
| - '*' | ||
|
|
||
| pr: none | ||
|
|
||
| pool: | ||
| vmImage: 'ubuntu-latest' | ||
|
|
||
| variables: | ||
| - group: link-cloud-variables | ||
| - name: project | ||
| value: 'DotNet/DMRP/DMRP.csproj' | ||
| - name: testProject | ||
| value: 'DotNet/ServiceTests/ServiceTests.csproj' | ||
| - name: registry-repo-Name | ||
| value: 'link-dmrp' | ||
| - name: dockerPath | ||
| value: '**/DotNet/DMRP/Dockerfile' | ||
| - name: serviceName | ||
| value: 'DMRP' | ||
| - name: projectDir | ||
| value: 'DotNet/DMRP' | ||
|
|
||
| steps: | ||
| - task: DotNetCoreCLI@2 | ||
| displayName: Restore | ||
| inputs: | ||
| command: restore | ||
| projects: '$(project)' | ||
|
|
||
| - task: Bash@3 | ||
| inputs: | ||
| targetType: 'inline' | ||
| script: | | ||
| GIT_COMMIT=$(git rev-parse --short HEAD) | ||
| echo "GIT_COMMIT: ${GIT_COMMIT}" | ||
| echo "##vso[task.setvariable variable=GIT_COMMIT]${GIT_COMMIT}" | ||
|
|
||
| - task: PythonScript@0 | ||
| displayName: "Inject Service Info" | ||
| inputs: | ||
| scriptSource: 'filePath' | ||
| scriptPath: '$(Build.SourcesDirectory)/Scripts/set_service_info.py' | ||
| workingDirectory: '$(Build.SourcesDirectory)' | ||
| arguments: './ "$(projectDir)" "$(GIT_COMMIT)" "$(Build.BuildNumber)"' | ||
|
|
||
| - task: DotNetCoreCLI@2 | ||
| displayName: Build | ||
| inputs: | ||
| command: build | ||
| projects: '$(project)' | ||
|
|
||
| - task: DotNetCoreCLI@2 | ||
| inputs: | ||
| command: 'test' | ||
| projects: '$(testProject)' | ||
| displayName: 'Run Tests' | ||
|
|
||
| - task: PowerShell@2 | ||
| inputs: | ||
| targetType: 'inline' | ||
| script: | | ||
| if ("$(Build.SourceBranch)" -like "*release/*") { | ||
| $myTag1 = "release-$(Build.SourceBranchName)-$(GIT_COMMIT)" | ||
| } | ||
| else { | ||
| $myTag1 = "$(Build.SourceBranchName)-$(GIT_COMMIT)" | ||
| } | ||
| Write-Host "##vso[task.setvariable variable=MyTag]$myTag1" | ||
| Write-Host "Set MyTag to: $myTag1" | ||
| - task: Docker@2 | ||
| displayName: "Build & Push DMRP Docker Image" | ||
| condition: always() | ||
| inputs: | ||
| containerRegistry: $(containerRegistry) # Variable Group | ||
| repository: $(registry-repo-name) | ||
| command: 'buildAndPush' | ||
| Dockerfile: $(dockerPath) | ||
| tags: | | ||
| latest | ||
| $(MyTag) | ||
| buildContext: '$(Build.Repository.LocalPath)' | ||
|
|
||
| - task: PublishPipelineArtifact@1 | ||
| inputs: | ||
| targetPath: '$(Build.ArtifactStagingDirectory)' | ||
| artifact: 'manifest' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| ο»Ώusing LantanaGroup.Link.LinkAdmin.BFF.Application.Models.Health; | ||
| using LantanaGroup.Link.LinkAdmin.BFF.Infrastructure.Logging; | ||
| using LantanaGroup.Link.Shared.Application.Models.Configs; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
| using Microsoft.Extensions.Options; | ||
| using System.Net.Http.Headers; | ||
|
|
||
| namespace LantanaGroup.Link.LinkAdmin.BFF.Application.Clients | ||
| { | ||
| public class DmrpService | ||
| { | ||
| private readonly ILogger<DmrpService> _logger; | ||
| private readonly HttpClient _client; | ||
| private readonly IOptions<ServiceRegistry> _serviceRegistry; | ||
|
|
||
| public DmrpService(ILogger<DmrpService> logger, HttpClient client, IOptions<ServiceRegistry> serviceRegistry) | ||
| { | ||
| _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
| _client = client ?? throw new ArgumentNullException(nameof(client)); | ||
| _serviceRegistry = serviceRegistry ?? throw new ArgumentNullException(nameof(serviceRegistry)); | ||
|
|
||
| InitHttpClient(); | ||
| } | ||
|
|
||
| public async Task<HttpResponseMessage> ServiceHealthCheck(CancellationToken cancellationToken) | ||
| { | ||
| // HTTP GET | ||
| HttpResponseMessage response = await _client.GetAsync($"health", cancellationToken); | ||
|
|
||
| return response; | ||
| } | ||
|
|
||
| public async Task<LinkServiceHealthReport> LinkServiceHealthCheck(CancellationToken cancellationToken) | ||
| { | ||
| // HTTP GET | ||
| try | ||
| { | ||
| var response = await _client.GetAsync($"health", cancellationToken); | ||
| var healthResult = await response.Content.ReadFromJsonAsync<LinkServiceHealthReport>(cancellationToken: cancellationToken); | ||
| if (healthResult is not null) healthResult.Service = "DMRP"; | ||
|
|
||
| return healthResult; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, "DMRP service health check failed"); | ||
| return new LinkServiceHealthReport { Service = "DMRP", Status = HealthStatus.Unhealthy }; | ||
| } | ||
| } | ||
|
|
||
| private void InitHttpClient() | ||
| { | ||
| //check if the service uri is set | ||
| if (string.IsNullOrEmpty(_serviceRegistry.Value.DmrpServiceUrl)) | ||
| { | ||
| _logger.LogGatewayServiceUriException("DMRP", "DMRP service uri is not set"); | ||
| throw new ArgumentNullException("DMRP Service URL is missing."); | ||
| } | ||
|
|
||
| _client.BaseAddress = new Uri(_serviceRegistry.Value.DmrpServiceUrl); | ||
| _client.DefaultRequestHeaders.Accept.Clear(); | ||
| _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
DotNet/Admin.BFF/Infrastructure/Health/DmrpServiceHealthCheck.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| ο»Ώusing LantanaGroup.Link.LinkAdmin.BFF.Application.Clients; | ||
| using LantanaGroup.Link.LinkAdmin.BFF.Infrastructure.Logging; | ||
| using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
|
|
||
| namespace LantanaGroup.Link.LinkAdmin.BFF.Infrastructure.Health | ||
| { | ||
| public class DmrpServiceHealthCheck : IHealthCheck | ||
| { | ||
| private readonly ILogger<DmrpServiceHealthCheck> _logger; | ||
| private readonly DmrpService _dmrpService; | ||
|
|
||
| public DmrpServiceHealthCheck(ILogger<DmrpServiceHealthCheck> logger, DmrpService dmrpService) | ||
| { | ||
| _logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
| _dmrpService = dmrpService ?? throw new ArgumentNullException(nameof(dmrpService)); | ||
| } | ||
|
|
||
| public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) | ||
| { | ||
| try | ||
| { | ||
| // make a request to the DMRP service health check | ||
| var response = await _dmrpService.ServiceHealthCheck(cancellationToken); | ||
|
|
||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| return HealthCheckResult.Healthy(); | ||
| } | ||
| else | ||
| { | ||
| return new HealthCheckResult(HealthStatus.Unhealthy, description: "DMRP service is not healthy"); | ||
| } | ||
|
|
||
| } | ||
| catch (HttpRequestException ex) | ||
| { | ||
| _logger.LogLinkServiceRequestException("DMRP", ex.Message); | ||
| return new HealthCheckResult(HealthStatus.Unhealthy, description: "HTTP request error."); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogLinkServiceRequestException("DMRP", ex.Message); | ||
| return new HealthCheckResult(HealthStatus.Unhealthy, description: "Failed to determine health status of the DMRP service."); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.