Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Client.Wasm/Components/StudentCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
</CardHeader>
<CardBody>
<UnorderedList Unstyled>
<UnorderedListItem>Номер <Strong>№X "Название лабораторной"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№Х "Название варианта"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Фамилией Именем 65ХХ</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://puginarug.com/">Ссылка на форк</Link></UnorderedListItem>
<UnorderedListItem>Номер <Strong>№2 «Балансировка»</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№4 «Кредитная заявка»</Strong></UnorderedListItem>
<UnorderedListItem>Выполнено <Strong>Горшениным Дмитрием 6511</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://github.com/dmgorshenin/cloud-development?tab=readme-ov-file">Ссылка на форк</Link></UnorderedListItem>
</UnorderedList>
</CardBody>
</Card>
12 changes: 6 additions & 6 deletions Client.Wasm/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
Expand All @@ -12,26 +12,26 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "http://localhost:5127",
"applicationUrl": "http://localhost:5128",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:7282;http://localhost:5127",
"applicationUrl": "https://localhost:7283;http://localhost:5128",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchBrowser": false,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
4 changes: 2 additions & 2 deletions Client.Wasm/wwwroot/appsettings.json
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"
}
68 changes: 68 additions & 0 deletions CloudDevelopment.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,84 @@ VisualStudioVersion = 17.14.36811.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client.Wasm", "Client.Wasm\Client.Wasm.csproj", "{AE7EEA74-2FE0-136F-D797-854FD87E022A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApplication.AppHost", "CreditApplication.AppHost\CreditApplication.AppHost.csproj", "{8D7BA58C-B453-616F-C170-8D20E1B277D5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApplication.Generator", "CreditApplication.Generator\CreditApplication.Generator.csproj", "{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApplication.ServiceDefaults", "CreditApplication.ServiceDefaults\CreditApplication.ServiceDefaults.csproj", "{3E99472D-C53C-A52E-DCDC-C663DE0B4459}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreditApplication.Gateway", "CreditApplication.Gateway\CreditApplication.Gateway.csproj", "{9455D133-4C88-48D6-AECD-6F84F7E17952}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|x64.ActiveCfg = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|x64.Build.0 = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|x86.ActiveCfg = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|x86.Build.0 = Debug|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.Build.0 = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|x64.ActiveCfg = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|x64.Build.0 = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|x86.ActiveCfg = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|x86.Build.0 = Release|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Debug|x64.ActiveCfg = Debug|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Debug|x64.Build.0 = Debug|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Debug|x86.ActiveCfg = Debug|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Debug|x86.Build.0 = Debug|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Release|Any CPU.Build.0 = Release|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Release|x64.ActiveCfg = Release|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Release|x64.Build.0 = Release|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Release|x86.ActiveCfg = Release|Any CPU
{8D7BA58C-B453-616F-C170-8D20E1B277D5}.Release|x86.Build.0 = Release|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Debug|x64.ActiveCfg = Debug|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Debug|x64.Build.0 = Debug|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Debug|x86.ActiveCfg = Debug|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Debug|x86.Build.0 = Debug|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Release|Any CPU.Build.0 = Release|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Release|x64.ActiveCfg = Release|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Release|x64.Build.0 = Release|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Release|x86.ActiveCfg = Release|Any CPU
{795D187F-BDDB-12D5-574B-DB27A6FAA1B2}.Release|x86.Build.0 = Release|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Debug|x64.ActiveCfg = Debug|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Debug|x64.Build.0 = Debug|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Debug|x86.ActiveCfg = Debug|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Debug|x86.Build.0 = Debug|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Release|Any CPU.Build.0 = Release|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Release|x64.ActiveCfg = Release|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Release|x64.Build.0 = Release|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Release|x86.ActiveCfg = Release|Any CPU
{3E99472D-C53C-A52E-DCDC-C663DE0B4459}.Release|x86.Build.0 = Release|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Debug|x64.ActiveCfg = Debug|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Debug|x64.Build.0 = Debug|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Debug|x86.ActiveCfg = Debug|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Debug|x86.Build.0 = Debug|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Release|Any CPU.Build.0 = Release|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Release|x64.ActiveCfg = Release|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Release|x64.Build.0 = Release|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Release|x86.ActiveCfg = Release|Any CPU
{9455D133-4C88-48D6-AECD-6F84F7E17952}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
25 changes: 25 additions & 0 deletions CreditApplication.AppHost/CreditApplication.AppHost.csproj
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.5.2" />

<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>
39 changes: 39 additions & 0 deletions CreditApplication.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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)
.WaitFor(redis);

var generator2 = builder.AddProject<Projects.CreditApplication_Generator>("generator-2")
.WithEndpoint("http", endpoint => endpoint.Port = 5102)
.WithReference(redis)
.WaitFor(redis);

var generator3 = builder.AddProject<Projects.CreditApplication_Generator>("generator-3")
.WithEndpoint("http", endpoint => endpoint.Port = 5103)
.WithReference(redis)
.WaitFor(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();
29 changes: 29 additions & 0 deletions CreditApplication.AppHost/Properties/launchSettings.json
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"
}
}
}
}
9 changes: 9 additions & 0 deletions CreditApplication.AppHost/appsettings.Development.json
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"
}
}
}
9 changes: 9 additions & 0 deletions CreditApplication.AppHost/appsettings.json
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 CreditApplication.Gateway/CreditApplication.Gateway.csproj
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Ocelot.LoadBalancer.LoadBalancers;
using Ocelot.Responses;
using Ocelot.ServiceDiscovery.Providers;
using Ocelot.Values;

namespace CreditApplication.Gateway.LoadBalancing;

public sealed class WeightedRandomLoadBalancer(
IServiceDiscoveryProvider serviceDiscovery,
IReadOnlyDictionary<string, double> weightsByName,
IReadOnlyDictionary<string, string> hostPortToName) : ILoadBalancer
{
private readonly IServiceDiscoveryProvider _serviceDiscovery = serviceDiscovery;
private readonly IReadOnlyDictionary<string, double> _weightsByName = weightsByName;
private readonly IReadOnlyDictionary<string, string> _hostPortToName = hostPortToName;

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(List<Service> services)
{
var weighted = services
.Select(s =>
{
var hostPort = $"{s.HostAndPort.DownstreamHost}:{s.HostAndPort.DownstreamPort}";
var name = _hostPortToName.TryGetValue(hostPort, out var n) ? n : hostPort;
var weight = _weightsByName.TryGetValue(name, out var w) ? w : 1.0;
return (Service: s, Weight: weight);
})
.ToList();

var total = weighted.Sum(x => x.Weight);

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;
}

return weighted[^1].Service;
}

// No connection tracking needed for stateless weighted random load balancing.
public void Release(ServiceHostAndPort hostAndPort) { }
}
Loading