-
Notifications
You must be signed in to change notification settings - Fork 52
Богачев Матвей Лаб. 2 Группа 6511 #99
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
45 commits
Select commit
Hold shift + click to select a range
fa78a55
создан
Matosik 1ae7749
генерация данных через Bogus
Matosik 6fb6c55
Создан нормальный генератор моделей, который относит модели к их прои…
Matosik 1b19de4
веб сервер
Matosik f182de1
изменен README под 1 ЛР
Matosik e82dee3
Вроде всё готово
Matosik f96b71b
Нормальные логи
Matosik 7af635e
sfdlhkj
Matosik 4de7479
Написаны Unit тесты
Matosik 839686a
Удалены ненужные дерективы using
Matosik 13d2baa
Добавлены описания
Matosik 5170a8d
значение ttl вынесено в appsetting.json
Matosik 0197853
удален ненужный файл
Matosik 990c578
delete string.Empty и добавлены описание описания(даже описания исклю…
Matosik 08d75a0
Удален не используемый класс остался только Dto. Надеюсь это никого н…
Matosik ab5a2c8
написан primary constructor
Matosik 9a94c4f
Seed => Id
Matosik 975f080
Удалены ненужные закомиченые исключения и один файл = один класс
Matosik 688ed74
лучший способ получать файл с производителями и моделями
Matosik 34c5ec2
Меньше пустых строк
Matosik b0651bb
VehicleModelGenerator теперь не генератор а просто закрузчик данных д…
Matosik 47f9b8f
JsonSerializerOptions вынесен в статическое поле
Matosik 47fb48c
теперь data не может быть null так как выбросится исключение
Matosik 1c1e4d2
Убрал лишнюю проверку
Matosik f49ba5e
primary конструктор
Matosik f1a7125
Удалено то чего быть не должно
Matosik 50be3f3
порт вынесен в appsetting.json
Matosik d5767dd
primary constructor
Matosik c6b4c9b
страшная табуляция превратилась в шедевр искусства
Matosik 3fc2ba7
Понижена гарантия валидации данных
Matosik 7ddadc5
вынес адрес клиента в appsetting.json
Matosik 0a0badb
ждем
Matosik 46b43a6
Удален ненужный проект
Matosik f00be80
Asp => Server
Matosik 850282c
Aspire.StackExchange.Redis.DistributedCaching
Matosik c1ddc10
cleanup code
Matosik ccfb2bb
fix
Matosik 2230a46
update readme.md
Matosik f16e060
ApiGateway with Ocelot
Matosik af13308
Ready
Matosik cf104f5
Booger AIDS
Matosik ce29877
рrename lab
Matosik b9ea43a
fix
Matosik c468fd7
Merge branch 'Lab2' of https://github.com/Matosik/cloud-development i…
Matosik b856429
Балансировщик снова работает
Matosik 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
| 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.6" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Aspire.ServiceDefaults\Aspire.ServiceDefaults.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,41 @@ | ||
| using Ocelot.LoadBalancer.LoadBalancers; | ||
| using Ocelot.Responses; | ||
| using Ocelot.ServiceDiscovery.Providers; | ||
| using Ocelot.Values; | ||
|
|
||
| namespace ApiGateway.Balancer; | ||
|
|
||
| public sealed class QueryBasedLoadBalancer( | ||
| IServiceDiscoveryProvider serviceDiscovery) : ILoadBalancer | ||
| { | ||
| public string Type => nameof(QueryBasedLoadBalancer); | ||
|
|
||
| public async Task<Response<ServiceHostAndPort>> LeaseAsync(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")); | ||
|
|
||
| var service = SelectByQuery(httpContext, services); | ||
| return new OkResponse<ServiceHostAndPort>(service.HostAndPort); | ||
| } | ||
|
|
||
| private static Service SelectByQuery(HttpContext httpContext, List<Service> services) | ||
| { | ||
| var idRaw = httpContext.Request.Query["id"].FirstOrDefault(); | ||
|
|
||
| if (!int.TryParse(idRaw, out var id)) | ||
| return services[0]; | ||
|
|
||
| var index = Math.Abs(id % services.Count); | ||
| return services[index]; | ||
| } | ||
|
|
||
| public void Release(ServiceHostAndPort hostAndPort) { } | ||
| } |
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,57 @@ | ||
| using ApiGateway.Balancer; | ||
| using Ocelot.DependencyInjection; | ||
| using Ocelot.Middleware; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.Configuration.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true); | ||
|
|
||
| var generators = builder.Configuration.GetSection("Generators").Get<string[]>() ?? []; | ||
|
|
||
| var overrides = new List<KeyValuePair<string, string?>>(); | ||
|
|
||
| for (var i = 0; i < generators.Length; i++) | ||
| { | ||
| var serviceName = generators[i]; | ||
| var url = builder.Configuration[$"services:{serviceName}:https:0"]; | ||
|
|
||
| if (string.IsNullOrWhiteSpace(url)) | ||
| continue; | ||
|
|
||
| if (!Uri.TryCreate(url, UriKind.Absolute, out var uri)) | ||
| continue; | ||
|
|
||
| overrides.Add(new KeyValuePair<string, string?>( | ||
| $"Routes:0:DownstreamHostAndPorts:{i}:Host", uri.Host)); | ||
|
|
||
| overrides.Add(new KeyValuePair<string, string?>( | ||
| $"Routes:0:DownstreamHostAndPorts:{i}:Port", uri.Port.ToString())); | ||
| } | ||
|
|
||
| if (overrides.Count != 0) | ||
| { | ||
| builder.Configuration.AddInMemoryCollection(overrides); | ||
| } | ||
|
|
||
| builder.Services.AddCors(options => | ||
| { | ||
| options.AddPolicy("ClientPolicy", policy => | ||
| { | ||
| policy | ||
| .AllowAnyOrigin() | ||
| .AllowAnyMethod() | ||
| .AllowAnyHeader(); | ||
| }); | ||
| }); | ||
|
|
||
| builder.Services | ||
| .AddOcelot(builder.Configuration) | ||
| .AddCustomLoadBalancer((route, sp) => | ||
| new QueryBasedLoadBalancer(sp)); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.UseCors("ClientPolicy"); | ||
|
|
||
| await app.UseOcelot(); | ||
| await app.RunAsync(); |
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,38 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "iisSettings": { | ||
| "windowsAuthentication": false, | ||
| "anonymousAuthentication": true, | ||
| "iisExpress": { | ||
| "applicationUrl": "http://localhost:21053", | ||
| "sslPort": 44384 | ||
| } | ||
| }, | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:5194", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:7141;http://localhost:5194", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| }, | ||
| "IIS Express": { | ||
| "commandName": "IISExpress", | ||
| "launchBrowser": true, | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
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,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "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,14 @@ | ||
| { | ||
| "ClientAddress": "https://localhost:7282", | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Ocelot": "Debug" | ||
| } | ||
| }, | ||
| "GlobalConfiguration": { | ||
| "BaseUrl": "https://localhost:8095" | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
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,21 @@ | ||
| { | ||
| "Generators": [ "back-0", "back-1", "back-2" ], | ||
| "Routes": [ | ||
| { | ||
| "DownstreamPathTemplate": "/contracts/vehicle", | ||
| "DownstreamScheme": "https", | ||
| "UpstreamPathTemplate": "/contracts/vehicle", | ||
| "UpstreamHttpMethod": [ "Get" ], | ||
| "DownstreamHostAndPorts": [ | ||
| { | ||
| "Host": "localhost", | ||
| "Port": 8090 | ||
| } | ||
| ], | ||
| "LoadBalancerOptions": { | ||
| "Type": "QueryBasedLoadBalancer" | ||
| } | ||
| } | ||
| ], | ||
| "GlobalConfiguration": {} | ||
| } | ||
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,22 @@ | ||
| var builder = DistributedApplication.CreateBuilder(args); | ||
| var redis = builder.AddRedis("cache").WithRedisInsight(); | ||
|
|
||
| var gateway = builder.AddProject<Projects.ApiGateway>("gateway") | ||
| .WithEndpoint("https", endpoint => endpoint.Port = 8095); | ||
|
|
||
| for (var i = 0; i < 3; i++) | ||
| { | ||
| var generator = builder.AddProject<Projects.Server>($"back-{i}") | ||
|
danlla marked this conversation as resolved.
|
||
| .WithEndpoint("https", endpoint => endpoint.Port = 8090+i) | ||
|
danlla marked this conversation as resolved.
|
||
| .WithReference(redis) | ||
| .WaitFor(redis); | ||
|
|
||
| gateway.WithReference(generator) | ||
| .WaitFor(generator); | ||
| } | ||
|
|
||
| builder.AddProject<Projects.Client_Wasm>("front") | ||
| .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,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.5.0" /> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UserSecretsId>332a680f-f1c5-49c8-a258-12e527af6b5e</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" Version="13.1.2" /> | ||
| <PackageReference Include="Aspire.Hosting.Redis" Version="13.1.2" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ApiGateway\ApiGateway.csproj" /> | ||
| <ProjectReference Include="..\Server\Server.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,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17077;http://localhost:15131", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21228", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22147" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15131", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19273", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20035" | ||
| } | ||
| } | ||
| } | ||
| } |
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,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "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" | ||
| } | ||
| } | ||
| } |
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,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireSharedProject>true</IsAspireSharedProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
|
|
||
| <PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.9.0" /> | ||
| <PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.5.0" /> | ||
| <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" /> | ||
| <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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.