-
Notifications
You must be signed in to change notification settings - Fork 12
Горшенин Дмитрий Лаб. 1 Группа 6511 #2
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8fd9d9d
Добавлен сервис генерации и кэширования кредитных заявок для первой л…
dmgorshenin e1db504
Update README.md
dmgorshenin c0518fa
Очистка кода
dmgorshenin 90ecc6e
Update README.md
dmgorshenin 8d9edea
Update README.md
dmgorshenin 85e73d2
Исправил правки
dmgorshenin 9e1bd91
Merge branch 'main' of https://github.com/dmgorshenin/cloud-development
dmgorshenin 7d74621
Забыл еще _logger убрать
dmgorshenin 089ed21
Лабораторная работа 2
dmgorshenin 700e4da
фикс правок
dmgorshenin 23f9ff6
Лабораторная 2
dmgorshenin 2f7c365
еще один коммит на слияние
dmgorshenin 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
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 |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| { | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*", | ||
| "BaseAddress": "https://localhost:7170/land-plot" | ||
| "BaseAddress": "http://localhost:5200/credit-application" | ||
| } |
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
25 changes: 25 additions & 0 deletions
25
CreditApplication.AppHost/CreditApplication.AppHost.csproj
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,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting" Version="9.5.2" /> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" Version="9.5.2" /> | ||
| <PackageReference Include="Aspire.Hosting.Redis" Version="9.5.2" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\CreditApplication.Gateway\CreditApplication.Gateway.csproj" /> | ||
| <ProjectReference Include="..\CreditApplication.Generator\CreditApplication.Generator.csproj" /> | ||
| <ProjectReference Include="..\Client.Wasm\Client.Wasm.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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,36 @@ | ||
| using Microsoft.Extensions.Hosting; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var redis = builder.AddRedis("redis"); | ||
|
|
||
| if (builder.Environment.IsDevelopment()) | ||
| redis.WithRedisCommander(); | ||
|
|
||
| var generator1 = builder.AddProject<Projects.CreditApplication_Generator>("generator-1") | ||
| .WithEndpoint("http", endpoint => endpoint.Port = 5101) | ||
| .WithReference(redis); | ||
|
|
||
| var generator2 = builder.AddProject<Projects.CreditApplication_Generator>("generator-2") | ||
| .WithEndpoint("http", endpoint => endpoint.Port = 5102) | ||
| .WithReference(redis); | ||
|
|
||
| var generator3 = builder.AddProject<Projects.CreditApplication_Generator>("generator-3") | ||
| .WithEndpoint("http", endpoint => endpoint.Port = 5103) | ||
| .WithReference(redis); | ||
|
|
||
| var gateway = builder.AddProject<Projects.CreditApplication_Gateway>("gateway") | ||
| .WithEndpoint("http", endpoint => endpoint.Port = 5200) | ||
| .WithReference(generator1) | ||
| .WithReference(generator2) | ||
| .WithReference(generator3) | ||
| .WithExternalHttpEndpoints() | ||
| .WaitFor(generator1) | ||
| .WaitFor(generator2) | ||
| .WaitFor(generator3); | ||
|
|
||
| builder.AddProject<Projects.Client_Wasm>("client") | ||
| .WithReference(gateway) | ||
| .WaitFor(gateway); | ||
|
|
||
| builder.Build().Run(); |
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,29 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17170;http://localhost:15170", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21170", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22170" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15170", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19170", | ||
| "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20170" | ||
| } | ||
| } | ||
| } | ||
| } |
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,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
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,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
CreditApplication.Gateway/CreditApplication.Gateway.csproj
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,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Ocelot" Version="23.3.3" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\CreditApplication.ServiceDefaults\CreditApplication.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
68 changes: 68 additions & 0 deletions
68
CreditApplication.Gateway/LoadBalancing/WeightedRandomLoadBalancer.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,68 @@ | ||
| using Ocelot.LoadBalancer.LoadBalancers; | ||
| using Ocelot.Responses; | ||
| using Ocelot.ServiceDiscovery.Providers; | ||
| using Ocelot.Values; | ||
|
|
||
| namespace CreditApplication.Gateway.LoadBalancing; | ||
|
|
||
| public sealed class WeightedRandomLoadBalancer : ILoadBalancer | ||
| { | ||
| private readonly IServiceDiscoveryProvider _serviceDiscovery; | ||
| private readonly IReadOnlyDictionary<string, double> _weights; | ||
|
|
||
| public WeightedRandomLoadBalancer( | ||
| IServiceDiscoveryProvider serviceDiscovery, | ||
| IReadOnlyDictionary<string, double> weights) | ||
| { | ||
| _serviceDiscovery = serviceDiscovery; | ||
| _weights = weights; | ||
| } | ||
|
|
||
| public async Task<Response<ServiceHostAndPort>> Lease(HttpContext httpContext) | ||
| { | ||
| var services = await _serviceDiscovery.GetAsync(); | ||
|
|
||
| if (services is null) | ||
| return new ErrorResponse<ServiceHostAndPort>( | ||
| new ServicesAreNullError("Service discovery returned null")); | ||
|
|
||
| if (services.Count == 0) | ||
| return new ErrorResponse<ServiceHostAndPort>( | ||
| new ServicesAreNullError("No downstream services are available")); | ||
|
|
||
| return new OkResponse<ServiceHostAndPort>(SelectByWeight(services).HostAndPort); | ||
| } | ||
|
|
||
| private Service SelectByWeight(IList<Service> services) | ||
| { | ||
| var weighted = services | ||
| .Select(s => ( | ||
| Service: s, | ||
| Weight: _weights.TryGetValue( | ||
| $"{s.HostAndPort.DownstreamHost}:{s.HostAndPort.DownstreamPort}", | ||
| out var w) ? w : 1.0)) | ||
| .ToList(); | ||
|
|
||
| var total = weighted.Sum(x => x.Weight); | ||
|
|
||
| // If all weights are zero or missing, fall back to uniform random selection. | ||
| if (total <= 0) | ||
| return services[Random.Shared.Next(services.Count)]; | ||
|
|
||
| var roll = Random.Shared.NextDouble() * total; | ||
| var cumulative = 0.0; | ||
|
|
||
| foreach (var (service, weight) in weighted) | ||
| { | ||
| cumulative += weight; | ||
| if (roll < cumulative) | ||
| return service; | ||
| } | ||
|
|
||
| // Guard against floating-point rounding: cumulative may fall infinitesimally short of total. | ||
| return weighted[^1].Service; | ||
| } | ||
|
|
||
| // No connection tracking needed for stateless weighted random load balancing. | ||
| public void Release(ServiceHostAndPort hostAndPort) { } | ||
| } |
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.