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
10 changes: 10 additions & 0 deletions ApiGateway/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
var app = builder.Build();

app.MapDefaultEndpoints();

app.MapGet("/", () => "Hello World!");

app.Run();
38 changes: 38 additions & 0 deletions ApiGateway/Properties/launchSettings.json
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:49541",
"sslPort": 44328
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5176",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7163;http://localhost:5176",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions ApiGateway/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions ApiGateway/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
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>№1 "Кэширование"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№5 "Сотрудник компании"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Дубовой Ксенией 6511</Strong> </UnorderedListItem>
<UnorderedListItem><Link To="https://github.com/kseniaDubova/cloud-development">Ссылка на форк</Link></UnorderedListItem>
</UnorderedList>
</CardBody>
</Card>
6 changes: 3 additions & 3 deletions Client.Wasm/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"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",
"environmentVariables": {
Expand All @@ -22,7 +22,7 @@
"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",
"environmentVariables": {
Expand All @@ -31,7 +31,7 @@
},
"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
16 changes: 8 additions & 8 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": ""
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"BaseAddress": "http://localhost:5212/api/CompanyEmployee"
}
28 changes: 26 additions & 2 deletions CloudDevelopment.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36811.4
# Visual Studio Version 18
VisualStudioVersion = 18.3.11520.95
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}") = "CompanyEmployee.ApiService", "CompanyEmployee.ApiService\CompanyEmployee.ApiService.csproj", "{744675CA-BC69-5513-0A1B-3BCC004F02F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompanyEmployee.AppHost", "CompanyEmployee.AppHost\CompanyEmployee.AppHost.csproj", "{B9ED18C6-0485-F2DF-93F0-2F0EACE5381F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompanyEmployee.ServiceDefaults", "CompanyEmployee.ServiceDefaults\CompanyEmployee.ServiceDefaults.csproj", "{60C547C0-C951-4270-1D2E-4BB68A5739B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompanyEmployee.ApiGateway", "CompanyEmployee.ApiGateway\CompanyEmployee.ApiGateway.csproj", "{D0087FC1-B713-A582-9A28-3814270CFDAD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +23,22 @@ Global
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Debug|Any CPU.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
{744675CA-BC69-5513-0A1B-3BCC004F02F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{744675CA-BC69-5513-0A1B-3BCC004F02F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{744675CA-BC69-5513-0A1B-3BCC004F02F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{744675CA-BC69-5513-0A1B-3BCC004F02F1}.Release|Any CPU.Build.0 = Release|Any CPU
{B9ED18C6-0485-F2DF-93F0-2F0EACE5381F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B9ED18C6-0485-F2DF-93F0-2F0EACE5381F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9ED18C6-0485-F2DF-93F0-2F0EACE5381F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9ED18C6-0485-F2DF-93F0-2F0EACE5381F}.Release|Any CPU.Build.0 = Release|Any CPU
{60C547C0-C951-4270-1D2E-4BB68A5739B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60C547C0-C951-4270-1D2E-4BB68A5739B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60C547C0-C951-4270-1D2E-4BB68A5739B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{60C547C0-C951-4270-1D2E-4BB68A5739B6}.Release|Any CPU.Build.0 = Release|Any CPU
{D0087FC1-B713-A582-9A28-3814270CFDAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0087FC1-B713-A582-9A28-3814270CFDAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0087FC1-B713-A582-9A28-3814270CFDAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D0087FC1-B713-A582-9A28-3814270CFDAD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
17 changes: 17 additions & 0 deletions CompanyEmployee.ApiGateway/CompanyEmployee.ApiGateway.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="24.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CompanyEmployee.ServiceDefaults\CompanyEmployee.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
56 changes: 56 additions & 0 deletions CompanyEmployee.ApiGateway/LoadBalancer/WeightedRoundRobin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Ocelot.LoadBalancer.Interfaces;
using Ocelot.Responses;
using Ocelot.Values;

namespace CompanyEmployee.ApiGateway.LoadBalancer;

public class WeightedRoundRobin : ILoadBalancer
{
private static readonly List<ServiceHostAndPort> _expandedList = [];
private static int _index = 0;
private static readonly object _lock = new();
private static bool _initialized = false;

public string Type => nameof(WeightedRoundRobin);

public WeightedRoundRobin(
List<ServiceHostAndPort> services,
IConfiguration config)
{
if (_initialized) return;

var weights = config
.GetSection("LoadBalancerWeights")
.Get<Dictionary<string, int>>() ?? [];
;

for (var i = 0; i < services.Count; i++)
{
var s = services[i];

var key = $"R{i + 1}";
var weight = weights.TryGetValue(key, out var w) ? w : 1;

for (var j = 0; j < weight; j++)
{
_expandedList.Add(s);
}
}

_initialized = true;
}

public Task<Response<ServiceHostAndPort>> LeaseAsync(HttpContext context)
{
lock (_lock)
{
var s = _expandedList[_index];
_index = (_index + 1) % _expandedList.Count;

return Task.FromResult<Response<ServiceHostAndPort>>(
new OkResponse<ServiceHostAndPort>(s));
}
}

public void Release(ServiceHostAndPort hostAndPort) { }
}
63 changes: 63 additions & 0 deletions CompanyEmployee.ApiGateway/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using CompanyEmployee.ApiGateway.LoadBalancer;
using CompanyEmployee.ServiceDefaults;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Values;

var builder = WebApplication.CreateBuilder(args).AddServiceDefaults();

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}:http:0"];

Console.WriteLine($"{serviceName} -> {url}");

if (string.IsNullOrWhiteSpace(url))
continue;

var uri = new Uri(url);

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

builder.Configuration.AddInMemoryCollection(overrides);

builder.Services
.AddOcelot(builder.Configuration)
.AddCustomLoadBalancer((route, _) =>
{
var config = builder.Configuration;

var services = route.DownstreamAddresses
.Select(h => new ServiceHostAndPort(h.Host, h.Port))
.ToList();

return new WeightedRoundRobin(services, config);
});

builder.Services.AddCors(options =>
{
options.AddPolicy("wasm", policy =>
{
policy.WithOrigins("https://localhost:7282")
.AllowAnyMethod()
.AllowAnyHeader();
});
});

var app = builder.Build();
app.UseCors("wasm");

await app.UseOcelot();

app.Run();
38 changes: 38 additions & 0 deletions CompanyEmployee.ApiGateway/Properties/launchSettings.json
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:26883",
"sslPort": 44388
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5212",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7092;http://localhost:5212",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
11 changes: 11 additions & 0 deletions CompanyEmployee.ApiGateway/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5212"
}
}
14 changes: 14 additions & 0 deletions CompanyEmployee.ApiGateway/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"LoadBalancerWeights": {
"R1": 1,
"R2": 2,
"R3": 3
},
"AllowedHosts": "*"
}
Loading