cleanup exceptions (hopefully)

This commit is contained in:
Daniel Balk 2023-04-03 00:15:12 +02:00
parent 708ae080a3
commit 7b6528b03f
15 changed files with 2314 additions and 82 deletions

View file

@ -43,7 +43,6 @@ public class DataContext : DbContext
public DbSet<AaPanel> AaPanels { get; set; }
public DbSet<Website> Websites { get; set; }
public DbSet<DdosAttack> DdosAttacks { get; set; }
public DbSet<CleanupException> CleanupExceptions { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{

View file

@ -20,4 +20,5 @@ public class Server
public NodeAllocation MainAllocation { get; set; } = null!;
public Node Node { get; set; } = null!;
public User Owner { get; set; } = null!;
public bool IsCleanupException { get; set; } = false;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,51 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Moonlight.App.Database.Migrations
{
/// <inheritdoc />
public partial class ChengedCleanupExceptionModel : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "CleanupExceptions",
type: "datetime(6)",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.CreateIndex(
name: "IX_CleanupExceptions_ServerId",
table: "CleanupExceptions",
column: "ServerId");
migrationBuilder.AddForeignKey(
name: "FK_CleanupExceptions_Servers_ServerId",
table: "CleanupExceptions",
column: "ServerId",
principalTable: "Servers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_CleanupExceptions_Servers_ServerId",
table: "CleanupExceptions");
migrationBuilder.DropIndex(
name: "IX_CleanupExceptions_ServerId",
table: "CleanupExceptions");
migrationBuilder.DropColumn(
name: "CreatedAt",
table: "CleanupExceptions");
}
}
}

View file

@ -0,0 +1,62 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Moonlight.App.Database.Migrations
{
/// <inheritdoc />
public partial class RemovedCleanupExceptionChangedServerModel : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CleanupExceptions");
migrationBuilder.AddColumn<bool>(
name: "IsCleanupException",
table: "Servers",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsCleanupException",
table: "Servers");
migrationBuilder.CreateTable(
name: "CleanupExceptions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
ServerId = table.Column<int>(type: "int", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
Note = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4")
},
constraints: table =>
{
table.PrimaryKey("PK_CleanupExceptions", x => x.Id);
table.ForeignKey(
name: "FK_CleanupExceptions_Servers_ServerId",
column: x => x.ServerId,
principalTable: "Servers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_CleanupExceptions_ServerId",
table: "CleanupExceptions",
column: "ServerId");
}
}
}

View file

@ -482,6 +482,9 @@ namespace Moonlight.App.Database.Migrations
b.Property<bool>("Installing")
.HasColumnType("tinyint(1)");
b.Property<bool>("IsCleanupException")
.HasColumnType("tinyint(1)");
b.Property<int>("MainAllocationId")
.HasColumnType("int");
@ -827,24 +830,6 @@ namespace Moonlight.App.Database.Migrations
b.ToTable("Websites");
});
modelBuilder.Entity("Moonlight.App.Models.Misc.CleanupException", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
b.Property<string>("Note")
.IsRequired()
.HasColumnType("longtext");
b.Property<int>("ServerId")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("CleanupExceptions");
});
modelBuilder.Entity("Moonlight.App.Database.Entities.Database", b =>
{
b.HasOne("Moonlight.App.Database.Entities.AaPanel", "AaPanel")

View file

@ -1,8 +0,0 @@
namespace Moonlight.App.Models.Misc;
public class CleanupException
{
public int Id { get; set; }
public int ServerId { get; set; }
public string Note { get; set; }
}

View file

@ -1,44 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Moonlight.App.Database;
using Moonlight.App.Models.Misc;
namespace Moonlight.App.Repositories;
public class CleanupExceptionRepository : IDisposable
{
private readonly DataContext DataContext;
public CleanupExceptionRepository(DataContext dataContext)
{
DataContext = dataContext;
}
public DbSet<CleanupException> Get()
{
return DataContext.CleanupExceptions;
}
public CleanupException Add(CleanupException cleanupException)
{
var x = DataContext.CleanupExceptions.Add(cleanupException).Entity;
DataContext.SaveChanges();
return x;
}
public void Update(CleanupException cleanupException)
{
DataContext.CleanupExceptions.Update(cleanupException);
DataContext.SaveChanges();
}
public void Delete(CleanupException cleanupException)
{
DataContext.CleanupExceptions.Remove(cleanupException);
DataContext.SaveChanges();
}
public void Dispose()
{
DataContext.Dispose();
}
}

View file

@ -104,7 +104,6 @@ public class CleanupService
// Get repos from dependency injection
var serverRepository = scope.ServiceProvider.GetRequiredService<ServerRepository>();
var nodeRepository = scope.ServiceProvider.GetRequiredService<NodeRepository>();
var cleanupExceptionRepository = scope.ServiceProvider.GetRequiredService<CleanupExceptionRepository>();
var nodeService = scope.ServiceProvider.GetRequiredService<NodeService>();
var imageRepo = scope.ServiceProvider.GetRequiredService<ImageRepository>();
var serverService = scope.ServiceProvider.GetRequiredService<ServerService>();
@ -114,7 +113,7 @@ public class CleanupService
.Include(x => x.Image)
.ToArray();
var nodes = nodeRepository.Get().ToArray();
var exceptions = cleanupExceptionRepository.Get().ToArray();
var exceptions = servers.Where(x => x.IsCleanupException);
var images = imageRepo.Get().ToArray();
var nodeCount = nodes.Count();
@ -228,7 +227,7 @@ public class CleanupService
var players = GetPlayers(serverData.Node, serverData.MainAllocation);
var stats = await serverService.GetDetails(server);
var exception = exceptions.FirstOrDefault(x => x.ServerId == server.Id) != null;
var exception = exceptions.FirstOrDefault(x => x.Id == server.Id) != null;
if (stats != null)
{

View file

@ -58,6 +58,8 @@
<_ContentIncludedByDefault Remove="wwwroot\css\site.css" />
<_ContentIncludedByDefault Remove="Shared\Components\Tables\Column.razor" />
<_ContentIncludedByDefault Remove="Shared\Components\Tables\Table.razor" />
<_ContentIncludedByDefault Remove="Shared\Views\Admin\Servers\Cleanup\Exceptions\Add.razor" />
<_ContentIncludedByDefault Remove="Shared\Views\Admin\Servers\Cleanup\Exceptions\Edit.razor" />
</ItemGroup>
<ItemGroup>

View file

@ -65,7 +65,6 @@ namespace Moonlight
builder.Services.AddScoped<AaPanelRepository>();
builder.Services.AddScoped<WebsiteRepository>();
builder.Services.AddScoped<DdosAttackRepository>();
builder.Services.AddScoped<CleanupExceptionRepository>();
builder.Services.AddScoped<AuditLogEntryRepository>();
builder.Services.AddScoped<ErrorLogEntryRepository>();

View file

@ -10,7 +10,9 @@
@implements IDisposable
<PageTitle><TL>Cleanup</TL></PageTitle>
<PageTitle>
<TL>Cleanup</TL>
</PageTitle>
<IsAdmin>
<div class="row g-5 g-xl-10 mb-5 mb-xl-10">
@ -25,8 +27,12 @@
<div class="d-flex align-items-center">
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersCleaned)</span>
<div class="fw-bold fs-6 text-white">
<span class="d-block"><TL>Servers</TL></span>
<span><TL>stopped</TL></span>
<span class="d-block">
<TL>Servers</TL>
</span>
<span>
<TL>stopped</TL>
</span>
</div>
</div>
</div>
@ -43,8 +49,12 @@
<div class="d-flex align-items-center">
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.CleanupsPerformed)</span>
<div class="fw-bold fs-6 text-white">
<span class="d-block"><TL>Cleanups</TL></span>
<span><TL>executed</TL></span>
<span class="d-block">
<TL>Cleanups</TL>
</span>
<span>
<TL>executed</TL>
</span>
</div>
</div>
</div>
@ -61,8 +71,12 @@
<div class="d-flex align-items-center">
<span class="fs-4hx text-white fw-bold me-6">@(CleanupService.ServersRunning)</span>
<div class="fw-bold fs-6 text-white">
<span class="d-block"><TL>Used clanup</TL></span>
<span><TL>Servers</TL></span>
<span class="d-block">
<TL>Used clanup</TL>
</span>
<span>
<TL>Servers</TL>
</span>
</div>
</div>
</div>
@ -142,6 +156,7 @@
@code
{
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)

View file

@ -111,6 +111,10 @@
<option value="@(DockerImages.IndexOf(image))">@(image.Name)</option>
}
</select>
<label class="form-label">
<TL>Cleanup exception</TL>
</label>
<input @bind="Server.IsCleanupException" class="form-control" type="checkbox" />
</div>
</div>
<div class="row mb-5">

View file

@ -427,3 +427,5 @@ Cleanup finished. Duration: 0.14 Minutes;Cleanup finished. Duration: 0.14 Minute
Cleanup finished. Duration: 0.09 Minutes;Cleanup finished. Duration: 0.09 Minutes
Cleanup finished. Duration: 0.1 Minutes;Cleanup finished. Duration: 0.1 Minutes
Cleanup finished. Duration: 0.11 Minutes;Cleanup finished. Duration: 0.11 Minutes
Cleanup Exceptions;Cleanup Exceptions
Server not found;Server not found