Commit 844e098e authored by Antonio Sarcevic's avatar Antonio Sarcevic 🌻
Browse files

Merge branch 'master' into e2e-ci

parents 01765d20 b0dd6180
......@@ -104,11 +104,9 @@ publish-services-dev:
variables:
IMAGE_TAG: latest-dev
script:
- docker buildx build -t $IMAGE_PREFIX/matchmaker:$IMAGE_TAG -f MatchMaker/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/matchmanager:$IMAGE_TAG -f MatchManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/gamemanager:$IMAGE_TAG -f GameManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/botmanager:$IMAGE_TAG -f BotManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/refereemanager:$IMAGE_TAG -f RefereeManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/usermanager:$IMAGE_TAG -f UserManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/tournamentsystemmanager:$IMAGE_TAG -f TournamentSystemManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/tournamentmanager:$IMAGE_TAG -f TournamentManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
......@@ -122,7 +120,7 @@ publish-connectors-dev:
variables:
IMAGE_TAG: latest-dev
script:
- docker buildx build -t $IMAGE_PREFIX/signalrhub:$IMAGE_TAG -f SignalRHub/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/signalrbot:$IMAGE_TAG -f BotSignal/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/signalrgui:$IMAGE_TAG -f GuiSignal/Dockerfile --platform linux/arm64,linux/amd64 --push .
only:
- master
......@@ -143,11 +141,9 @@ publish-services-release:
variables:
IMAGE_TAG: latest
script:
- docker buildx build -t $IMAGE_PREFIX/matchmaker:$IMAGE_TAG -f MatchMaker/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/matchmanager:$IMAGE_TAG -f MatchManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/gamemanager:$IMAGE_TAG -f GameManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/botmanager:$IMAGE_TAG -f BotManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/refereemanager:$IMAGE_TAG -f RefereeManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/usermanager:$IMAGE_TAG -f UserManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/tournamentsystemmanager:$IMAGE_TAG -f TournamentSystemManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/tournamentmanager:$IMAGE_TAG -f TournamentManager/Dockerfile --platform linux/arm64,linux/amd64 --push .
......@@ -161,7 +157,7 @@ publish-connecters-release:
variables:
IMAGE_TAG: latest
script:
- docker buildx build -t $IMAGE_PREFIX/signalrhub:$IMAGE_TAG -f SignalRHub/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/signalbot:$IMAGE_TAG -f BotSignal/Dockerfile --platform linux/arm64,linux/amd64 --push .
- docker buildx build -t $IMAGE_PREFIX/signalrgui:$IMAGE_TAG -f GuiSignal/Dockerfile --platform linux/arm64,linux/amd64 --push .
only:
- release
......
......@@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
<PackageReference Include="Botolution.ApiMsgLibrary" Version="1.1.1" />
<PackageReference Include="Botolution.ApiMsgLibrary" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.11">
......@@ -20,7 +20,7 @@
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.2" />
<PackageReference Include="RabbitMQ.Client.Core.DependencyInjection" Version="4.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.0.2" />
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.1.3" />
<PackageReference Include="IdentityModel" Version="5.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.11" />
</ItemGroup>
......
......@@ -15,7 +15,7 @@ namespace BotManager.Controller
{
[Route("api/v1/bots")]
[ApiController]
[Authorize]
[Authorize(Roles = "Student")]
public class BotsController : ControllerBase
{
private readonly IBotManagerService _botManagerService;
......
......@@ -36,9 +36,9 @@ namespace BotManager.DB.Repositories.Implementations
return await dbContext.Bots.AsNoTracking().Where(@where).ToListAsync();
}
/* Updates the Status of a bot Online/Offline and the Adress */
public void UpdateStatus(Bot bot)
public async Task UpdateStatusAsync(Bot bot)
{
using var dbContext = _contextFactory.CreateDbContext();
await using var dbContext = _contextFactory.CreateDbContext();
var dbBot = dbContext.Bots.AsNoTracking()
.FirstOrDefault(tmpBot => tmpBot.Token.Equals(bot.Token));
if (dbBot is not null) //Time to create
......
......@@ -11,7 +11,7 @@ namespace BotManager.DB.Repositories.Interfaces
Task<Bot> GetAsync(string botId);
Task<List<Bot>> GetAllAsync();
Task<List<Bot>> GetAllAsync(Expression<Func<Bot, bool>> where);
void UpdateStatus(Bot bot);
Task UpdateStatusAsync(Bot bot);
void InsertBot(Bot bot);
void Update(Bot bot);
public bool checkToken(Bot bot);
......
using AutoMapper;
using System.Threading.Tasks;
using AutoMapper;
using BotManager.Service;
using Microsoft.Extensions.Logging;
using RabbitMQ.Client.Core.DependencyInjection.MessageHandlers;
......@@ -6,7 +7,7 @@ using RabbitMQ.Client.Events;
namespace BotManager.MQ.MessageHandler
{
public abstract class AbstractMessageHandler : IMessageHandler
public abstract class AbstractMessageHandler : IAsyncMessageHandler
{
protected readonly IBotManagerService BotManagerService;
protected readonly ILogger Logger;
......@@ -20,6 +21,6 @@ namespace BotManager.MQ.MessageHandler
Mapper = mapper;
}
public abstract void Handle(BasicDeliverEventArgs eventArgs, string matchingRoute);
public abstract Task Handle(BasicDeliverEventArgs eventArgs, string matchingRoute);
}
}
\ No newline at end of file
using AutoMapper;
using System.Threading.Tasks;
using AutoMapper;
using BotManager.DB.Model;
using BotManager.Service;
using Botolution.ApiMsgLibrary.ApiMessages.DeregisterBot;
......@@ -16,11 +17,11 @@ namespace BotManager.MQ.MessageHandler
{
}
public override void Handle(BasicDeliverEventArgs eventArgs, string matchingRoute)
public override async Task Handle(BasicDeliverEventArgs eventArgs, string matchingRoute)
{
var msg = JsonConvert.DeserializeObject<DeregisterBotRequest>(eventArgs.GetMessage());
var bot = Mapper.Map<Bot>(msg.Bot);
BotManagerService.DeregisterBot(bot);
await BotManagerService.DeregisterBotAsync(bot);
}
}
}
\ No newline at end of file
using AutoMapper;
using System.Threading.Tasks;
using AutoMapper;
using BotManager.DB.Model;
using BotManager.Service;
using Botolution.ApiMsgLibrary.ApiMessages.RegisterBot;
......@@ -16,13 +17,12 @@ namespace BotManager.MQ.MessageHandler
{
}
public override void Handle(BasicDeliverEventArgs eventArgs, string matchingRoute)
public override async Task Handle(BasicDeliverEventArgs eventArgs, string matchingRoute)
{
var replayAddress = eventArgs.BasicProperties.ReplyTo;
var msg = JsonConvert.DeserializeObject<RegisterBotRequest>(eventArgs.GetMessage());
var bot = Mapper.Map<Bot>(msg.Bot);
BotManagerService.RegisterBot(bot, replayAddress);
await BotManagerService.RegisterBotAsync(bot);
}
}
}
\ No newline at end of file
using System.Text;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using RabbitMQ.Client.Core.DependencyInjection.Services;
namespace BotManager.MQ.Service.Producing
{
public class AbstractProducingService
{
protected readonly ILogger Logger;
private IQueueService _queueService;
protected AbstractProducingService(ILogger<ProducingService> logger)
{
Logger = logger;
}
public void SetQueueService(IQueueService queueService)
{
_queueService = queueService;
}
protected async void Send<T>(T @object, string exchangeName, string routingKey, string replayAddress = null,
string msgType = null) where T : class
{
var basicProperties = _queueService.Channel.CreateBasicProperties();
basicProperties.ReplyTo = replayAddress;
basicProperties.Type = msgType;
basicProperties.Persistent = true;
basicProperties.ContentType = "application/json";
var json = JsonConvert.SerializeObject(@object);
var bytes = Encoding.UTF8.GetBytes(json);
await _queueService.SendAsync(bytes, basicProperties, exchangeName, routingKey);
}
}
}
\ No newline at end of file
namespace BotManager.MQ.Service.Producing
{
public interface IProducingService
{
void SendRegisterBotResponse(string replayAddress);
}
}
\ No newline at end of file
using Botolution.ApiMsgLibrary.ApiMessages.RegisterBot;
using Microsoft.Extensions.Logging;
namespace BotManager.MQ.Service.Producing
{
public class ProducingService : AbstractProducingService, IProducingService
{
public ProducingService(ILogger<ProducingService> logger) : base(logger)
{
}
public void SendRegisterBotResponse(string replayAddress)
{
var msg = new RegisterBotResponse();
Send(msg, "amq.topic", $"{replayAddress}.RegisterBotResponse");
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using BotManager.DB.Model;
using BotManager.DB.Repositories.Interfaces;
using BotManager.MQ.Service.Producing;
using Microsoft.Extensions.Logging;
namespace BotManager.Service
......@@ -12,32 +10,27 @@ namespace BotManager.Service
{
private readonly IBotRepository _botRepository;
private readonly ILogger _logger;
private readonly IProducingService _producingService;
public BotManagerService(ILogger<BotManagerService> logger, IBotRepository botRepository,
IProducingService producingService)
public BotManagerService(ILogger<BotManagerService> logger, IBotRepository botRepository)
{
_logger = logger;
_botRepository = botRepository;
_producingService = producingService;
}
public void DeregisterBot(Bot bot)
public async Task DeregisterBotAsync(Bot bot)
{
_botRepository.UpdateStatus(bot);
await _botRepository.UpdateStatusAsync(bot);
}
/* Ändert den Status eines Bots zu Online*/
public void RegisterBot(Bot bot, string replayAddress)
public async Task RegisterBotAsync(Bot bot)
{
if (!_botRepository.checkToken(bot))
{
return;
}
bot.Address = replayAddress;
_botRepository.UpdateStatus(bot);
_producingService.SendRegisterBotResponse(replayAddress);
await _botRepository.UpdateStatusAsync(bot);
}
public void NewBot(Bot bot)
......
......@@ -6,9 +6,9 @@ namespace BotManager.Service
{
public interface IBotManagerService
{
void DeregisterBot(Bot msg);
Task DeregisterBotAsync(Bot msg);
void RegisterBot(Bot bot, string replayAddress);
Task RegisterBotAsync(Bot bot);
public void NewBot(Bot bot);
......
using BotManager.DB;
using BotManager.DB.Model;
using BotManager.DB.Repositories.Implementations;
using BotManager.DB.Repositories.Interfaces;
using BotManager.Mapper;
using BotManager.MQ.MessageHandler;
using BotManager.MQ.Service.Consuming;
using BotManager.MQ.Service.Producing;
using BotManager.Service;
using IdentityModel;
using Microsoft.AspNetCore.Authentication.JwtBearer;
......@@ -17,8 +15,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
using RabbitMQ.Client.Core.DependencyInjection;
using RabbitMQ.Client.Core.DependencyInjection.Services;
using IProducingService = BotManager.MQ.Service.Producing.IProducingService;
namespace BotManager
{
......@@ -47,6 +43,8 @@ namespace BotManager
NameClaimType = JwtClaimTypes.Name,
};
});
services.AddAuthorization();
services.AddCors(options =>
{
......@@ -63,28 +61,24 @@ namespace BotManager
var rabbitMqSection = _configuration.GetSection("RabbitMq");
var exchangeSection = _configuration.GetSection("RabbitMqExchange");
services.AddRabbitMqClient(rabbitMqSection)
.AddExchange("amq.topic", true, exchangeSection)
.AddMessageHandlerSingleton<DeregisterBotMessageHandler>("*.DeregisterBotRequest")
.AddMessageHandlerSingleton<RegisterBotMessageHandler>("*.RegisterBotRequest");
.AddExchange("amq.direct", true, exchangeSection)
.AddAsyncMessageHandlerSingleton<DeregisterBotMessageHandler>("DeregisterBotRequest")
.AddAsyncMessageHandlerSingleton<RegisterBotMessageHandler>("RegisterBotRequest");
services.AddSingleton<IHostedService, ConsumingService>();
services.AddControllers();
services.AddMvc().AddNewtonsoftJson();
services.AddAutoMapper(typeof(BotProfile));
services.AddSingleton<IBotRepository, BotRepository>();
services.AddSingleton<IProducingService, ProducingService>();
services.AddSingleton<IBotManagerService, BotManagerService>();
DbRegistrar.RegisterDbContextAsFactory(_configuration, services);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IQueueService queueService,
IProducingService producingService, IDbContextFactory<BotManagerContext> contextFactory)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDbContextFactory<BotManagerContext> contextFactory)
{
DbMigrator.MigrateDbOnStartup(contextFactory);
(producingService as AbstractProducingService)?.SetQueueService(queueService);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
......
......@@ -5,14 +5,16 @@
<UserSecretsId>f0b40b76-b230-4d94-b1d7-8ae0d57bd22e</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
<RootNamespace>BotSignal</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Botolution.ApiMsgLibrary" Version="1.1.1" />
<PackageReference Include="Botolution.ApiMsgLibrary" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.5" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="RabbitMQ.Client.Core.DependencyInjection" Version="4.3.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="3.1.3" />
</ItemGroup>
<ItemGroup>
......
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
......@@ -7,17 +5,17 @@ EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["nuget.config", "SignalRHub/"]
COPY ["SignalRHub/SignalRHub.csproj", "SignalRHub/"]
RUN dotnet restore "SignalRHub/SignalRHub.csproj"
COPY ["nuget.config", "BotSignal/"]
COPY ["BotSignal/BotSignal.csproj", "BotSignal/"]
RUN dotnet restore "BotSignal/BotSignal.csproj"
COPY . .
WORKDIR "/src/SignalRHub"
RUN dotnet build "SignalRHub.csproj" -c Release -o /app/build
WORKDIR "/src/BotSignal"
RUN dotnet build "BotSignal.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SignalRHub.csproj" -c Release -o /app/publish
RUN dotnet publish "BotSignal.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SignalRHub.dll"]
\ No newline at end of file
ENTRYPOINT ["dotnet", "BotSignal.dll"]
\ No newline at end of file
using System;
using System.Threading.Tasks;
using Botolution.ApiMsgLibrary.ApiMessages.MakeMove;
using Botolution.ApiMsgLibrary.Events;
using BotSignal.MQ.Service.Producing;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Serilog;
using SignalRHub.MQ.Service.Producing;
namespace SignalRHub.Hubs
namespace BotSignal.Hubs
{
public class BotHub : Hub
{
private readonly IProducingService _producingService;
private readonly ILogger<BotHub> _logger;
......@@ -22,58 +19,38 @@ namespace SignalRHub.Hubs
_producingService = producingService;
}
//Bot Calls this Function to connect to SignalRHub with Botname, Game and Address? etc.
// public Task RegisterBot(string name, string game, string address)
// {
// _producingService.SendRegisterBotRequest(name, game, address, "Online", 5000);
// }
// public Task DeregisterBot(string name, string game, string address)
// {
// _producingService.SendDeregisterBotRequest(name, game, address, "Offline");
// }
public override async Task OnConnectedAsync()
{
// await Groups.AddToGroupAsync(Context.ConnectionId, "SignalR Users");
string connectionId = Context.ConnectionId;
// string name = Context.User.Identity.Name;
// var dict = Context.Items;
// var game = dict["game"];
// var address = dict["address"];
var connectionId = Context.ConnectionId;
string bottoken = Context.GetHttpContext().Request.Query["bottoken"];
// await Groups.AddToGroupAsync(connectionId, botname);
// _producingService.SendRegisterBotRequest(name, (String)game, (String)address, "Online", 5000);
_logger.LogInformation($"Someone tries to connect to SignalR Hub, ConnectionId: {connectionId}, Token: {bottoken}");
_producingService.SendRegisterBotRequest( connectionId, "Online", bottoken,5000);
_producingService.SendRegisterBotRequest(connectionId, "Online", bottoken, 5000);
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
// await Groups.RemoveFromGroupAsync(Context.ConnectionId, "SignalR Users");
string connectionId = Context.ConnectionId;
// string name = Context.UserIdentifier;
// var dict = Context.Items;
// var game = dict["game"];
// var address = dict["address"];
var connectionId = Context.ConnectionId;
string bottoken = Context.GetHttpContext().Request.Query["bottoken"];
// _producingService.SendDeregisterBotRequest(name, (String)game, (String)address, "Offline");
_logger.LogInformation("Someone wants to get lost of SignalR Hub");
_producingService.SendDeregisterBotRequest( connectionId, "Offline",bottoken);
_producingService.SendDeregisterBotRequest(connectionId, "Offline", bottoken);
await base.OnDisconnectedAsync(exception);
}
public async Task MakeMove(string makeMoveResponse)
public async Task TurnProposed(string turnProposed)
{
_logger.LogInformation("Received makeMoveResponse: " + makeMoveResponse);
MakeMoveResponse resp = JsonConvert.DeserializeObject<MakeMoveResponse>(makeMoveResponse);
resp.ConnectionId = Context.ConnectionId;
_producingService.SendMakeMoveResponse(resp);
_logger.LogInformation($"Received turnProposed: {turnProposed}");
var resp = JsonConvert.DeserializeObject<TurnProposed>(turnProposed);
if (resp != null)
{
resp.BotAddress = Context.ConnectionId;
_producingService.SendTurnProposed(resp);
}
}
}
}
\ No newline at end of file
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using BotSignal.Hubs;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
using RabbitMQ.Client.Core.DependencyInjection.MessageHandlers;
using RabbitMQ.Client.Events;
using SignalRHub.Hubs;
namespace SignalRHub.MQ.MessageHandler
namespace BotSignal.MQ.MessageHandler
{
public abstract class AbstractMessageHandler : IMessageHandler
public abstract class AbstractMessageHandler : IAsyncMessageHandler
{
protected readonly ILogger Logger;
protected readonly IHubContext<BotHub> Hubcontext;
......@@ -17,6 +18,6 @@ namespace SignalRHub.MQ.MessageHandler
Hubcontext = hubcontext;
}
public abstract void Handle(BasicDeliverEventArgs eventArgs, string matchingRoute);
public abstract Task Handle(BasicDeliverEventArgs eventArgs, string matchingRoute);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment