Skip to content

Карпачева Полина Лаб. 2 Группа 6512#33

Open
PolinaKrp wants to merge 35 commits intoitsecd:mainfrom
PolinaKrp:main
Open

Карпачева Полина Лаб. 2 Группа 6512#33
PolinaKrp wants to merge 35 commits intoitsecd:mainfrom
PolinaKrp:main

Conversation

@PolinaKrp
Copy link

ФИО: Карпачева Полина
Номер группы: 6512
Номер лабораторной: 2
Номер варианта: 22
Краткое описание предметной области: Товар на складе
Краткое описание добавленных фич: Добавлен Api Gateway, реплики

image

@github-actions github-actions bot added In progress Код в процессе проверки Lab 2 Лабораторная №2. Балансировка нагрузки labels Mar 8, 2026
@github-actions github-actions bot requested a review from Gwymlas March 8, 2026 00:39
Copy link

@Gwymlas Gwymlas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправить лабораторную работу, сейчас балансировщик никак не участвует


namespace AspireApp.ApiGateway.LoadBalancing;

public class WeightedRandomLoadBalancer : ILoadBalancer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нет summary

Comment on lines +23 to +35
public WeightedRandomLoadBalancer()
{
_servicesProvider = null!;
_weights = null!;
}

public WeightedRandomLoadBalancer(
Func<Task<List<Service>>> servicesProvider,
Dictionary<string, int> weights) : this()
{
_servicesProvider = servicesProvider;
_weights = weights;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Использовать праймари конструктор

private readonly Dictionary<string, int> _weights;
private readonly Random _random = new();

public string Type => throw new NotImplementedException();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type должен совпадать с "Type" в ocelot

public async Task<Response<ServiceHostAndPort>> LeaseAsync(HttpContext httpContext)
{
var services = await _servicesProvider();
if (services == null || services.Count == 0)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Убрать лишнюю проверку services == null

Comment on lines +71 to +75
public class ServicesAreEmptyError : Error
{
public ServicesAreEmptyError(string message)
: base(message, OcelotErrorCode.ServicesAreEmptyError, 503) { }
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В отдельный файл

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавить сюда cors и убрать из сервиса

Comment on lines +5 to +24
var api0 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-0")
.WithReference(cache)
.WithEnvironment("REPLICA_ID", "0")
.WaitFor(cache);

var api1 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-1")
.WithReference(cache)
.WithEnvironment("REPLICA_ID", "1")
.WaitFor(cache);

var api2 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-2")
.WithReference(cache)
.WithEnvironment("REPLICA_ID", "2")
.WaitFor(cache);

var gateway = builder.AddProject("api-gateway", "../AspireApp.ApiGateway/AspireApp.ApiGateway.csproj")
.WithReference(api0)
.WithReference(api1)
.WithReference(api2)
.WaitFor(api0).WaitFor(api1).WaitFor(api2);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Переместить в цикл

Comment on lines +10 to +13
var api1 = builder.AddProject<Projects.AspireApp_ApiService>("warehouse-api-1")
.WithReference(cache)
.WithEnvironment("REPLICA_ID", "1")
.WaitFor(cache);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Будут запущены не на тех портах, которые указаны в ocelot.json

Comment on lines +27 to +28
.WithReference(gateway)
.WithEnvironment("BaseAddress", gateway.GetEndpoint("http"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не нужен, BaseAddress будет браться из appsettings

Comment on lines +20 to +26
var apiBaseUrl = builder.Configuration["BaseAddress"]
?? throw new InvalidOperationException("BaseAddress not configured");

builder.Services.AddHttpClient("ApiClient", client =>
{
client.BaseAddress = new Uri(apiBaseUrl);
}); No newline at end of file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вроде это дублирование кода выше
BaseAddress в appsettings остался прежним, то есть клиент обращается на один из запущенных сервисов в обход апи гейтвея

@PolinaKrp PolinaKrp requested a review from Gwymlas March 21, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

In progress Код в процессе проверки Lab 2 Лабораторная №2. Балансировка нагрузки

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants