HiveMind PoC + P1, P3 fixes
This commit is contained in:
committed by
Kirill
parent
1744425d5f
commit
9f6c1f5135
@@ -1,4 +1,5 @@
|
||||
using DevOpsProject.CommunicationControl.API.DTO.Client.Request;
|
||||
using Asp.Versioning;
|
||||
using DevOpsProject.CommunicationControl.API.DTO.Client.Request;
|
||||
using DevOpsProject.CommunicationControl.Logic.Services.Interfaces;
|
||||
using DevOpsProject.Shared.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -6,22 +7,24 @@ using Microsoft.Extensions.Options;
|
||||
|
||||
namespace DevOpsProject.CommunicationControl.API.Controllers
|
||||
{
|
||||
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Route("api/client")]
|
||||
[Route("api/v{version:apiVersion}/client")]
|
||||
public class ClientController : Controller
|
||||
{
|
||||
private readonly ICommunicationControlService _communicationControlService;
|
||||
private readonly IOptionsMonitor<OperationalAreaConfig> _operationalAreaConfig;
|
||||
private readonly ILogger<ClientController> _logger;
|
||||
|
||||
public ClientController(ICommunicationControlService communicationControlService, IOptionsMonitor<OperationalAreaConfig> operationalAreaConfig)
|
||||
public ClientController(ICommunicationControlService communicationControlService, IOptionsMonitor<OperationalAreaConfig> operationalAreaConfig, ILogger<ClientController> logger)
|
||||
{
|
||||
_communicationControlService = communicationControlService;
|
||||
_operationalAreaConfig = operationalAreaConfig;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("area")]
|
||||
public async Task<IActionResult> GetOperationalArea()
|
||||
public IActionResult GetOperationalArea()
|
||||
{
|
||||
return Ok(_operationalAreaConfig.CurrentValue);
|
||||
}
|
||||
@@ -51,16 +54,27 @@ namespace DevOpsProject.CommunicationControl.API.Controllers
|
||||
}
|
||||
|
||||
[HttpPatch("hive")]
|
||||
public async Task<IActionResult> SendBulkHiveMovingSignal(MoveHivesRequest request)
|
||||
public IActionResult SendBulkHiveMovingSignal(MoveHivesRequest request)
|
||||
{
|
||||
if (request?.Hives == null || !request.Hives.Any())
|
||||
return BadRequest("No hive IDs provided.");
|
||||
|
||||
foreach (var id in request.Hives)
|
||||
{
|
||||
Task.Run(async () => await _communicationControlService.SendHiveControlSignal(id, request.Destination));
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await _communicationControlService.SendHiveControlSignal(id, request.Destination);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Failed to send control signal for HiveID: {id}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return Accepted("Hives are being moved asynchronously.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using DevOpsProject.CommunicationControl.API.DTO.Hive.Request;
|
||||
using DevOpsProject.CommunicationControl.API.DTO.Hive.Response;
|
||||
using Asp.Versioning;
|
||||
using DevOpsProject.CommunicationControl.Logic.Services.Interfaces;
|
||||
using DevOpsProject.Shared.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DevOpsProject.CommunicationControl.API.Controllers
|
||||
{
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Route("api/hive")]
|
||||
[Route("api/v{version:apiVersion}/hive")]
|
||||
public class HiveController : Controller
|
||||
{
|
||||
private readonly ICommunicationControlService _communicationControlService;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace DevOpsProject.CommunicationControl.API.DTO.Hive.Request
|
||||
{
|
||||
public class HiveConnectRequest
|
||||
{
|
||||
public string HiveIP { get; set; }
|
||||
public int HivePort { get; set; }
|
||||
public string HiveID { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using DevOpsProject.Shared.Enums;
|
||||
using DevOpsProject.Shared.Models;
|
||||
|
||||
namespace DevOpsProject.CommunicationControl.API.DTO.Hive.Request
|
||||
{
|
||||
public class HiveTelemetryRequest
|
||||
{
|
||||
public string HiveID { get; set; }
|
||||
public Location Location { get; set; }
|
||||
public float Speed { get; set; }
|
||||
public float Height { get; set; }
|
||||
public State State { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using DevOpsProject.Shared.Models;
|
||||
|
||||
namespace DevOpsProject.CommunicationControl.API.DTO.Hive.Response
|
||||
{
|
||||
public class HiveConnectResponse
|
||||
{
|
||||
public bool ConnectResult { get; set; }
|
||||
public HiveOperationalArea OperationalArea { get;set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace DevOpsProject.CommunicationControl.API.DTO.Hive.Response
|
||||
{
|
||||
public class HiveTelemetryResponse
|
||||
{
|
||||
public DateTime Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,20 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<Nullable>disable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="DTO\Client\Response\**" />
|
||||
<Content Remove="DTO\Client\Response\**" />
|
||||
<EmbeddedResource Remove="DTO\Client\Response\**" />
|
||||
<None Remove="DTO\Client\Response\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Asp.Versioning.Http" Version="8.1.0" />
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.1" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
@@ -22,8 +31,4 @@
|
||||
<ProjectReference Include="..\DevOpsProject.Shared\DevOpsProject.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DTO\Client\Response\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using Asp.Versioning;
|
||||
using DevOpsProject.CommunicationControl.API.DI;
|
||||
using DevOpsProject.CommunicationControl.API.Middleware;
|
||||
using DevOpsProject.Shared.Clients;
|
||||
using DevOpsProject.Shared.Configuration;
|
||||
using DevOpsProject.Shared.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Polly;
|
||||
using Polly.Extensions.Http;
|
||||
using Serilog;
|
||||
@@ -18,10 +21,31 @@ internal class Program
|
||||
.ReadFrom.Services(services)
|
||||
.Enrich.FromLogContext());
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddApiVersioning(options =>
|
||||
{
|
||||
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
options.AssumeDefaultVersionWhenUnspecified = true;
|
||||
options.ReportApiVersions = true;
|
||||
options.ApiVersionReader = ApiVersionReader.Combine(
|
||||
new UrlSegmentApiVersionReader(),
|
||||
new HeaderApiVersionReader("X-Api-Version")
|
||||
);
|
||||
}).AddApiExplorer(options =>
|
||||
{
|
||||
options.GroupNameFormat = "'v'VVV";
|
||||
options.SubstituteApiVersionInUrl = true;
|
||||
});
|
||||
|
||||
// TODO: consider this approach
|
||||
builder.Services.AddControllers().AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = null;
|
||||
}); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "CommunicationControl - V1", Version = "v1.0" });
|
||||
});
|
||||
|
||||
// TODO: LATER - ADD OpenTelemtry
|
||||
|
||||
@@ -29,13 +53,12 @@ internal class Program
|
||||
builder.Services.AddCommunicationControlLogic();
|
||||
|
||||
builder.Services.Configure<OperationalAreaConfig>(builder.Configuration.GetSection("OperationalArea"));
|
||||
builder.Services.AddSingleton<IOptionsMonitor<OperationalAreaConfig>, OptionsMonitor<OperationalAreaConfig>>();
|
||||
|
||||
builder.Services.Configure<ComControlCommunicationConfiguration>(builder.Configuration.GetSection("CommunicationConfiguration"));
|
||||
|
||||
var hiveRetryPolicy = HttpPolicyExtensions
|
||||
.HandleTransientHttpError()
|
||||
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||
builder.Services.AddHttpClient<HiveHttpClient>()
|
||||
builder.Services.AddHttpClient<CommunicationControlHttpClient>()
|
||||
.AddPolicyHandler(hiveRetryPolicy);
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@
|
||||
},
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Console"
|
||||
"Name": "Console",
|
||||
"Args": {
|
||||
"restrictedToMinimumLevel": "Information"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "File",
|
||||
@@ -18,7 +21,8 @@
|
||||
"path": "Logs/log-.txt",
|
||||
"rollingInterval": "Day",
|
||||
"rollOnFileSizeLimit": true,
|
||||
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
|
||||
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact",
|
||||
"restrictedToMinimumLevel": "Warning"
|
||||
}
|
||||
}
|
||||
],
|
||||
@@ -45,6 +49,10 @@
|
||||
"PingInterval_MS": 15000
|
||||
|
||||
},
|
||||
"CommunicationConfiguration": {
|
||||
"RequestScheme": "http",
|
||||
"HiveMindPath": "api/v1"
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Urls": "http://0.0.0.0:8080"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user