Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,4 @@ FodyWeavers.xsd
*.msi
*.msix
*.msm
*.msp
*.msp
17 changes: 17 additions & 0 deletions Api.Gateway/Api.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="24.1.0" />
</ItemGroup>

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

</Project>
6 changes: 6 additions & 0 deletions Api.Gateway/Api.Gateway.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>
33 changes: 33 additions & 0 deletions Api.Gateway/LoadBalancers/QueryBased.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Ocelot.LoadBalancer.Interfaces;
using Ocelot.Responses;
using Ocelot.Values;

namespace Api.Gateway.LoadBalancers;

/// <summary>
/// Балансировщик нагрузки на основе query-параметра id
/// Определяет реплику по остатку от деления идентификатора на число реплик
/// </summary>
/// <param name="services">Делегат для получения списка доступных реплик</param>
public class QueryBased(Func<Task<List<Service>>> services) : ILoadBalancer
{
public string Type => nameof(QueryBased);

public async Task<Response<ServiceHostAndPort>> LeaseAsync(HttpContext httpContext)
{
var availableServices = await services.Invoke();
var replicaCount = availableServices.Count;

var replicaIndex = 0;

if (httpContext.Request.Query.TryGetValue("id", out var rawId)
&& int.TryParse(rawId, out var employeeId))
{
replicaIndex = Math.Abs(employeeId) % replicaCount;
}

return new OkResponse<ServiceHostAndPort>(availableServices[replicaIndex].HostAndPort);
}

public void Release(ServiceHostAndPort hostAndPort) { }
}
30 changes: 30 additions & 0 deletions Api.Gateway/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Api.Gateway.LoadBalancers;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.Services.AddServiceDiscovery();
builder.Configuration.AddJsonFile("ocelot.json", optional: false, reloadOnChange: true);
builder.Services.AddOcelot()
.AddCustomLoadBalancer<QueryBased>((_, _, discoveryProvider) => new(discoveryProvider.GetAsync));

var clientOrigin = builder.Configuration["ClientOrigin"]
?? throw new InvalidOperationException("ClientOrigin is not configured");

builder.Services.AddCors(options => options.AddDefaultPolicy(policy =>
{
policy.WithOrigins(clientOrigin);
policy.WithMethods("GET");
policy.AllowAnyHeader();
}));

var app = builder.Build();

app.UseCors();
app.MapDefaultEndpoints();

await app.UseOcelot();

app.Run();
38 changes: 38 additions & 0 deletions Api.Gateway/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:11915",
"sslPort": 44365
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5162",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7027;http://localhost:5162",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions Api.Gateway/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
10 changes: 10 additions & 0 deletions Api.Gateway/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ClientOrigin": "https://localhost:7282"
}
20 changes: 20 additions & 0 deletions Api.Gateway/ocelot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Routes": [
{
"DownstreamPathTemplate": "/api/employees",
"DownstreamScheme": "https",
"DownstreamHostAndPorts": [
{ "Host": "localhost", "Port": 5100 },
{ "Host": "localhost", "Port": 5101 },
{ "Host": "localhost", "Port": 5102 },
{ "Host": "localhost", "Port": 5103 },
{ "Host": "localhost", "Port": 5104 }
],
"UpstreamPathTemplate": "/employees",
"UpstreamHttpMethod": [ "Get" ],
"LoadBalancerOptions": {
"Type": "QueryBased"
}
}
]
}
6 changes: 6 additions & 0 deletions Client.Wasm/Client.Wasm.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>
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>№3 "Интеграционное тестирование"</Strong></UnorderedListItem>
<UnorderedListItem>Вариант <Strong>№49 "Сотрудник компании"</Strong></UnorderedListItem>
<UnorderedListItem>Выполнена <Strong>Панюшкиным Андрем 6513</Strong></UnorderedListItem>
<UnorderedListItem><Link To="https://github.com/Santas7/cloud-development/tree/main">Ссылка на форк</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
2 changes: 1 addition & 1 deletion Client.Wasm/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
}
},
"AllowedHosts": "*",
"BaseAddress": ""
"BaseAddress": "https://localhost:7027/employees"
}
86 changes: 61 additions & 25 deletions CloudDevelopment.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
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}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {90FE6B04-8381-437E-893A-FEBA1DA10AEE}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
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}") = "EmployeeApp.AppHost", "EmployeeApp\EmployeeApp.AppHost\EmployeeApp.AppHost.csproj", "{2EF7E965-1A57-4198-93B5-5E5F63EAA4B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeApp.ServiceDefaults", "EmployeeApp\EmployeeApp.ServiceDefaults\EmployeeApp.ServiceDefaults.csproj", "{2FA6E085-0B95-101F-0B19-42856D8FFBF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeApp.Api", "EmployeeApp.Api\EmployeeApp.Api.csproj", "{4FE86887-5370-BEE6-70F2-476C725D7719}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api.Gateway", "Api.Gateway\Api.Gateway.csproj", "{C99E72F4-9BA7-7D56-C88E-FB28534EFCB6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "File.Service", "File.Service\File.Service.csproj", "{DF944664-05C9-E01F-B262-C8B381C1EFE1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeApp.AppHost.Tests", "EmployeeApp\EmployeeApp.AppHost.Tests\EmployeeApp.AppHost.Tests.csproj", "{F48C9AC7-767C-441D-897A-87B061B88A5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
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}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE7EEA74-2FE0-136F-D797-854FD87E022A}.Release|Any CPU.Build.0 = Release|Any CPU
{2EF7E965-1A57-4198-93B5-5E5F63EAA4B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EF7E965-1A57-4198-93B5-5E5F63EAA4B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EF7E965-1A57-4198-93B5-5E5F63EAA4B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EF7E965-1A57-4198-93B5-5E5F63EAA4B2}.Release|Any CPU.Build.0 = Release|Any CPU
{2FA6E085-0B95-101F-0B19-42856D8FFBF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2FA6E085-0B95-101F-0B19-42856D8FFBF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2FA6E085-0B95-101F-0B19-42856D8FFBF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2FA6E085-0B95-101F-0B19-42856D8FFBF9}.Release|Any CPU.Build.0 = Release|Any CPU
{4FE86887-5370-BEE6-70F2-476C725D7719}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FE86887-5370-BEE6-70F2-476C725D7719}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FE86887-5370-BEE6-70F2-476C725D7719}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FE86887-5370-BEE6-70F2-476C725D7719}.Release|Any CPU.Build.0 = Release|Any CPU
{C99E72F4-9BA7-7D56-C88E-FB28534EFCB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C99E72F4-9BA7-7D56-C88E-FB28534EFCB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C99E72F4-9BA7-7D56-C88E-FB28534EFCB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C99E72F4-9BA7-7D56-C88E-FB28534EFCB6}.Release|Any CPU.Build.0 = Release|Any CPU
{DF944664-05C9-E01F-B262-C8B381C1EFE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF944664-05C9-E01F-B262-C8B381C1EFE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF944664-05C9-E01F-B262-C8B381C1EFE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF944664-05C9-E01F-B262-C8B381C1EFE1}.Release|Any CPU.Build.0 = Release|Any CPU
{F48C9AC7-767C-441D-897A-87B061B88A5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F48C9AC7-767C-441D-897A-87B061B88A5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F48C9AC7-767C-441D-897A-87B061B88A5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F48C9AC7-767C-441D-897A-87B061B88A5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {90FE6B04-8381-437E-893A-FEBA1DA10AEE}
EndGlobalSection
EndGlobal
27 changes: 27 additions & 0 deletions EmployeeApp.Api/EmployeeApp.Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="9.5.2" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="4.0.2.17" />
<PackageReference Include="Bogus" Version="35.6.5" />
<PackageReference Include="LocalStack.Client" Version="2.0.0" />
<PackageReference Include="LocalStack.Client.Extensions" Version="2.0.0" />
</ItemGroup>

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

<ItemGroup>
<Folder Include="Services\" />
<Folder Include="Entities\" />
<Folder Include="Messaging\" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions EmployeeApp.Api/EmployeeApp.Api.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>
Loading