mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2026-01-14 05:50:30 +01:00
Compare commits
4 Commits
wip-forge
...
feb0612124
| Author | SHA1 | Date | |
|---|---|---|---|
|
feb0612124
|
|||
|
25babbbc29
|
|||
|
93fde594a4
|
|||
|
e4dbb18584
|
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Text;
|
||||||
using System.Text;
|
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
using Phantom.Agent.Minecraft.Instance;
|
||||||
using Phantom.Agent.Minecraft.Java;
|
using Phantom.Agent.Minecraft.Java;
|
||||||
using Phantom.Agent.Minecraft.Server;
|
using Phantom.Agent.Minecraft.Server;
|
||||||
@@ -12,7 +11,7 @@ public abstract class BaseLauncher : IServerLauncher {
|
|||||||
private readonly InstanceProperties instanceProperties;
|
private readonly InstanceProperties instanceProperties;
|
||||||
|
|
||||||
protected string MinecraftVersion => instanceProperties.ServerVersion;
|
protected string MinecraftVersion => instanceProperties.ServerVersion;
|
||||||
protected string InstanceFolder => instanceProperties.InstanceFolder;
|
|
||||||
private protected BaseLauncher(InstanceProperties instanceProperties) {
|
private protected BaseLauncher(InstanceProperties instanceProperties) {
|
||||||
this.instanceProperties = instanceProperties;
|
this.instanceProperties = instanceProperties;
|
||||||
}
|
}
|
||||||
@@ -52,14 +51,17 @@ public abstract class BaseLauncher : IServerLauncher {
|
|||||||
|
|
||||||
var processConfigurator = new ProcessConfigurator {
|
var processConfigurator = new ProcessConfigurator {
|
||||||
FileName = javaRuntimeExecutable.ExecutablePath,
|
FileName = javaRuntimeExecutable.ExecutablePath,
|
||||||
WorkingDirectory = InstanceFolder,
|
WorkingDirectory = instanceProperties.InstanceFolder,
|
||||||
RedirectInput = true,
|
RedirectInput = true,
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
var processArguments = processConfigurator.ArgumentList;
|
var processArguments = processConfigurator.ArgumentList;
|
||||||
PrepareJvmArguments(serverJar).Build(processArguments);
|
PrepareJvmArguments(serverJar).Build(processArguments);
|
||||||
PrepareJavaProcessArguments(processArguments, serverJar.FilePath);
|
processArguments.Add("-jar");
|
||||||
|
processArguments.Add(serverJar.FilePath);
|
||||||
|
processArguments.Add("nogui");
|
||||||
|
|
||||||
var process = processConfigurator.CreateProcess();
|
var process = processConfigurator.CreateProcess();
|
||||||
var instanceProcess = new InstanceProcess(instanceProperties, process);
|
var instanceProcess = new InstanceProcess(instanceProperties, process);
|
||||||
|
|
||||||
@@ -97,11 +99,6 @@ public abstract class BaseLauncher : IServerLauncher {
|
|||||||
|
|
||||||
private protected virtual void CustomizeJvmArguments(JvmArgumentBuilder arguments) {}
|
private protected virtual void CustomizeJvmArguments(JvmArgumentBuilder arguments) {}
|
||||||
|
|
||||||
protected virtual void PrepareJavaProcessArguments(Collection<string> processArguments, string serverJarFilePath) {
|
|
||||||
processArguments.Add("-jar");
|
|
||||||
processArguments.Add(serverJarFilePath);
|
|
||||||
processArguments.Add("nogui");
|
|
||||||
}
|
|
||||||
private protected virtual Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
private protected virtual Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
||||||
return Task.FromResult(new ServerJarInfo(serverJarPath));
|
return Task.FromResult(new ServerJarInfo(serverJarPath));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
using System.Collections.ObjectModel;
|
|
||||||
using Phantom.Agent.Minecraft.Instance;
|
|
||||||
using Phantom.Agent.Minecraft.Java;
|
|
||||||
using Serilog;
|
|
||||||
|
|
||||||
namespace Phantom.Agent.Minecraft.Launcher.Types;
|
|
||||||
|
|
||||||
public sealed class ForgeLauncher : BaseLauncher {
|
|
||||||
public ForgeLauncher(InstanceProperties instanceProperties) : base(instanceProperties) {}
|
|
||||||
|
|
||||||
private protected override void CustomizeJvmArguments(JvmArgumentBuilder arguments) {
|
|
||||||
arguments.AddProperty("terminal.ansi", "true"); // TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void PrepareJavaProcessArguments(Collection<string> processArguments, string serverJarFilePath) {
|
|
||||||
if (OperatingSystem.IsWindows()) {
|
|
||||||
processArguments.Add("@libraries/net/minecraftforge/forge/1.20.1-47.2.0/win_args.txt");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
processArguments.Add("@libraries/net/minecraftforge/forge/1.20.1-47.2.0/unix_args.txt");
|
|
||||||
}
|
|
||||||
|
|
||||||
processArguments.Add("nogui");
|
|
||||||
}
|
|
||||||
|
|
||||||
private protected override Task<ServerJarInfo> PrepareServerJar(ILogger logger, string serverJarPath, CancellationToken cancellationToken) {
|
|
||||||
return Task.FromResult(new ServerJarInfo(Path.Combine(InstanceFolder, "run.sh")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -97,7 +97,6 @@ sealed class InstanceManagerActor : ReceiveActor<InstanceManagerActor.ICommand>
|
|||||||
IServerLauncher launcher = configuration.MinecraftServerKind switch {
|
IServerLauncher launcher = configuration.MinecraftServerKind switch {
|
||||||
MinecraftServerKind.Vanilla => new VanillaLauncher(properties),
|
MinecraftServerKind.Vanilla => new VanillaLauncher(properties),
|
||||||
MinecraftServerKind.Fabric => new FabricLauncher(properties),
|
MinecraftServerKind.Fabric => new FabricLauncher(properties),
|
||||||
MinecraftServerKind.Forge => new ForgeLauncher(properties),
|
|
||||||
_ => InvalidLauncher.Instance,
|
_ => InvalidLauncher.Instance,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ sealed record Variables(
|
|||||||
try {
|
try {
|
||||||
return LoadOrThrow();
|
return LoadOrThrow();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PhantomLogger.Root.Fatal("{}", e.Message);
|
PhantomLogger.Root.Fatal(e.Message);
|
||||||
throw StopProcedureException.Instance;
|
throw StopProcedureException.Instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ public sealed partial record Agent(
|
|||||||
[property: MemoryPackOrder(0)] Guid AgentGuid,
|
[property: MemoryPackOrder(0)] Guid AgentGuid,
|
||||||
[property: MemoryPackOrder(1)] AgentConfiguration Configuration,
|
[property: MemoryPackOrder(1)] AgentConfiguration Configuration,
|
||||||
[property: MemoryPackOrder(2)] ImmutableArray<byte> ConnectionKey,
|
[property: MemoryPackOrder(2)] ImmutableArray<byte> ConnectionKey,
|
||||||
[property: MemoryPackOrder(3)] AgentRuntimeInfo RuntimeInfo,
|
[property: MemoryPackOrder(3)] AgentRuntimeInfo? RuntimeInfo,
|
||||||
[property: MemoryPackOrder(4)] AgentStats? Stats,
|
[property: MemoryPackOrder(4)] AgentStats? Stats,
|
||||||
[property: MemoryPackOrder(5)] IAgentConnectionStatus ConnectionStatus
|
[property: MemoryPackOrder(5)] IAgentConnectionStatus ConnectionStatus
|
||||||
) {
|
) {
|
||||||
[MemoryPackIgnore]
|
[MemoryPackIgnore]
|
||||||
public RamAllocationUnits? AvailableMemory => RuntimeInfo.MaxMemory - Stats?.RunningInstanceMemory;
|
public RamAllocationUnits? AvailableMemory => RuntimeInfo?.MaxMemory - Stats?.RunningInstanceMemory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ namespace Phantom.Common.Data.Web.Agent;
|
|||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
[MemoryPackable(GenerateType.VersionTolerant)]
|
||||||
public sealed partial record AgentRuntimeInfo(
|
public sealed partial record AgentRuntimeInfo(
|
||||||
[property: MemoryPackOrder(0)] AgentVersionInfo? VersionInfo = null,
|
[property: MemoryPackOrder(0)] ushort ProtocolVersion,
|
||||||
[property: MemoryPackOrder(1)] ushort? MaxInstances = null,
|
[property: MemoryPackOrder(1)] string BuildVersion,
|
||||||
[property: MemoryPackOrder(2)] RamAllocationUnits? MaxMemory = null,
|
[property: MemoryPackOrder(2)] ushort MaxInstances,
|
||||||
[property: MemoryPackOrder(3)] AllowedPorts? AllowedServerPorts = null,
|
[property: MemoryPackOrder(3)] RamAllocationUnits MaxMemory,
|
||||||
[property: MemoryPackOrder(4)] AllowedPorts? AllowedRconPorts = null
|
[property: MemoryPackOrder(4)] AllowedPorts? AllowedServerPorts = null,
|
||||||
|
[property: MemoryPackOrder(5)] AllowedPorts? AllowedRconPorts = null
|
||||||
) {
|
) {
|
||||||
public static AgentRuntimeInfo From(AgentInfo agentInfo) {
|
public static AgentRuntimeInfo From(AgentInfo agentInfo) {
|
||||||
return new AgentRuntimeInfo(new AgentVersionInfo(agentInfo.ProtocolVersion, agentInfo.BuildVersion), agentInfo.MaxInstances, agentInfo.MaxMemory, agentInfo.AllowedServerPorts, agentInfo.AllowedRconPorts);
|
return new AgentRuntimeInfo(agentInfo.ProtocolVersion, agentInfo.BuildVersion, agentInfo.MaxInstances, agentInfo.MaxMemory, agentInfo.AllowedServerPorts, agentInfo.AllowedRconPorts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using MemoryPack;
|
|
||||||
|
|
||||||
namespace Phantom.Common.Data.Web.Agent;
|
|
||||||
|
|
||||||
[MemoryPackable(GenerateType.VersionTolerant)]
|
|
||||||
public readonly partial record struct AgentVersionInfo(
|
|
||||||
[property: MemoryPackOrder(0)] ushort ProtocolVersion,
|
|
||||||
[property: MemoryPackOrder(1)] string BuildVersion
|
|
||||||
);
|
|
||||||
@@ -3,5 +3,4 @@
|
|||||||
public enum MinecraftServerKind : ushort {
|
public enum MinecraftServerKind : ushort {
|
||||||
Vanilla = 1,
|
Vanilla = 1,
|
||||||
Fabric = 2,
|
Fabric = 2,
|
||||||
Forge = 3,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,356 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using System.Text.Json;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
using Phantom.Controller.Database;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Phantom.Controller.Database.Postgres.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(ApplicationDbContext))]
|
|
||||||
[Migration("20251228053557_AgentFieldNullability")]
|
|
||||||
partial class AgentFieldNullability
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "9.0.9")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.AgentEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("AgentGuid")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<byte[]>("AuthSecret")
|
|
||||||
.HasMaxLength(12)
|
|
||||||
.HasColumnType("bytea");
|
|
||||||
|
|
||||||
b.Property<string>("BuildVersion")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<int?>("MaxInstances")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int?>("MaxMemory")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<int?>("ProtocolVersion")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("AgentGuid");
|
|
||||||
|
|
||||||
b.ToTable("Agents", "agents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.AuditLogEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<long>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("bigint");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
|
|
||||||
|
|
||||||
b.Property<JsonDocument>("Data")
|
|
||||||
.HasColumnType("jsonb");
|
|
||||||
|
|
||||||
b.Property<string>("EventType")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("SubjectId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("SubjectType")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<Guid?>("UserGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<DateTime>("UtcTime")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("UserGuid");
|
|
||||||
|
|
||||||
b.ToTable("AuditLog", "system");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.EventLogEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("EventGuid")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid?>("AgentGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<JsonDocument>("Data")
|
|
||||||
.HasColumnType("jsonb");
|
|
||||||
|
|
||||||
b.Property<string>("EventType")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("SubjectId")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("SubjectType")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<DateTime>("UtcTime")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.HasKey("EventGuid");
|
|
||||||
|
|
||||||
b.ToTable("EventLog", "system");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.InstanceEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("InstanceGuid")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("AgentGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("InstanceName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<Guid>("JavaRuntimeGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("JvmArguments")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<bool>("LaunchAutomatically")
|
|
||||||
.HasColumnType("boolean");
|
|
||||||
|
|
||||||
b.Property<int>("MemoryAllocation")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<string>("MinecraftServerKind")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("MinecraftVersion")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<int>("RconPort")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("ServerPort")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("InstanceGuid");
|
|
||||||
|
|
||||||
b.ToTable("Instances", "agents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.PermissionEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<string>("Id")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Permissions", "identity");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.RoleEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("RoleGuid")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("RoleGuid");
|
|
||||||
|
|
||||||
b.ToTable("Roles", "identity");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.RolePermissionEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("RoleGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("PermissionId")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("RoleGuid", "PermissionId");
|
|
||||||
|
|
||||||
b.HasIndex("PermissionId");
|
|
||||||
|
|
||||||
b.ToTable("RolePermissions", "identity");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.UserAgentAccessEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("UserGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("AgentGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("UserGuid", "AgentGuid");
|
|
||||||
|
|
||||||
b.HasIndex("AgentGuid");
|
|
||||||
|
|
||||||
b.ToTable("UserAgentAccess", "identity");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.UserEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("UserGuid")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<string>("PasswordHash")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("UserGuid");
|
|
||||||
|
|
||||||
b.HasIndex("Name")
|
|
||||||
.IsUnique();
|
|
||||||
|
|
||||||
b.ToTable("Users", "identity");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.UserPermissionEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("UserGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<string>("PermissionId")
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("UserGuid", "PermissionId");
|
|
||||||
|
|
||||||
b.HasIndex("PermissionId");
|
|
||||||
|
|
||||||
b.ToTable("UserPermissions", "identity");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.UserRoleEntity", b =>
|
|
||||||
{
|
|
||||||
b.Property<Guid>("UserGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.Property<Guid>("RoleGuid")
|
|
||||||
.HasColumnType("uuid");
|
|
||||||
|
|
||||||
b.HasKey("UserGuid", "RoleGuid");
|
|
||||||
|
|
||||||
b.HasIndex("RoleGuid");
|
|
||||||
|
|
||||||
b.ToTable("UserRoles", "identity");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.AuditLogEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.UserEntity", "User")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UserGuid")
|
|
||||||
.OnDelete(DeleteBehavior.SetNull);
|
|
||||||
|
|
||||||
b.Navigation("User");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.RolePermissionEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.PermissionEntity", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("PermissionId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.RoleEntity", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("RoleGuid")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.UserAgentAccessEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.AgentEntity", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("AgentGuid")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.UserEntity", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UserGuid")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.UserPermissionEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.PermissionEntity", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("PermissionId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.UserEntity", null)
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UserGuid")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("Phantom.Controller.Database.Entities.UserRoleEntity", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.RoleEntity", "Role")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("RoleGuid")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("Phantom.Controller.Database.Entities.UserEntity", "User")
|
|
||||||
.WithMany()
|
|
||||||
.HasForeignKey("UserGuid")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Role");
|
|
||||||
|
|
||||||
b.Navigation("User");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace Phantom.Controller.Database.Postgres.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class AgentFieldNullability : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AlterColumn<int>(
|
|
||||||
name: "ProtocolVersion",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "integer",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(int),
|
|
||||||
oldType: "integer");
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<int>(
|
|
||||||
name: "MaxMemory",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "integer",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(int),
|
|
||||||
oldType: "integer");
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<int>(
|
|
||||||
name: "MaxInstances",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "integer",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(int),
|
|
||||||
oldType: "integer");
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<string>(
|
|
||||||
name: "BuildVersion",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "text",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(string),
|
|
||||||
oldType: "text");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AlterColumn<int>(
|
|
||||||
name: "ProtocolVersion",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "integer",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
oldClrType: typeof(int),
|
|
||||||
oldType: "integer",
|
|
||||||
oldNullable: true);
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<int>(
|
|
||||||
name: "MaxMemory",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "integer",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
oldClrType: typeof(int),
|
|
||||||
oldType: "integer",
|
|
||||||
oldNullable: true);
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<int>(
|
|
||||||
name: "MaxInstances",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "integer",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: 0,
|
|
||||||
oldClrType: typeof(int),
|
|
||||||
oldType: "integer",
|
|
||||||
oldNullable: true);
|
|
||||||
|
|
||||||
migrationBuilder.AlterColumn<string>(
|
|
||||||
name: "BuildVersion",
|
|
||||||
schema: "agents",
|
|
||||||
table: "Agents",
|
|
||||||
type: "text",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: "",
|
|
||||||
oldClrType: typeof(string),
|
|
||||||
oldType: "text",
|
|
||||||
oldNullable: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -34,19 +34,20 @@ namespace Phantom.Controller.Database.Postgres.Migrations
|
|||||||
.HasColumnType("bytea");
|
.HasColumnType("bytea");
|
||||||
|
|
||||||
b.Property<string>("BuildVersion")
|
b.Property<string>("BuildVersion")
|
||||||
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<int?>("MaxInstances")
|
b.Property<int>("MaxInstances")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<int?>("MaxMemory")
|
b.Property<int>("MaxMemory")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<string>("Name")
|
b.Property<string>("Name")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<int?>("ProtocolVersion")
|
b.Property<int>("ProtocolVersion")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.HasKey("AgentGuid");
|
b.HasKey("AgentGuid");
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Phantom.Common.Data;
|
using Phantom.Common.Data;
|
||||||
using Phantom.Common.Data.Web.Agent;
|
|
||||||
using Phantom.Utils.Rpc;
|
using Phantom.Utils.Rpc;
|
||||||
|
|
||||||
namespace Phantom.Controller.Database.Entities;
|
namespace Phantom.Controller.Database.Entities;
|
||||||
@@ -14,18 +13,14 @@ public sealed class AgentEntity {
|
|||||||
public Guid AgentGuid { get; init; }
|
public Guid AgentGuid { get; init; }
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public ushort? ProtocolVersion { get; set; }
|
public ushort ProtocolVersion { get; set; }
|
||||||
public string? BuildVersion { get; set; }
|
public string BuildVersion { get; set; }
|
||||||
public ushort? MaxInstances { get; set; }
|
public ushort MaxInstances { get; set; }
|
||||||
public RamAllocationUnits? MaxMemory { get; set; }
|
public RamAllocationUnits MaxMemory { get; set; }
|
||||||
|
|
||||||
[MaxLength(AuthSecret.Length)]
|
[MaxLength(AuthSecret.Length)]
|
||||||
public AuthSecret? AuthSecret { get; set; }
|
public AuthSecret? AuthSecret { get; set; }
|
||||||
|
|
||||||
public AgentConfiguration Configuration => new (Name);
|
|
||||||
public AgentVersionInfo? VersionInfo => ProtocolVersion is {} protocolVersion && BuildVersion is {} buildVersion ? new AgentVersionInfo(protocolVersion, buildVersion) : null;
|
|
||||||
public AgentRuntimeInfo RuntimeInfo => new (VersionInfo, MaxInstances, MaxMemory);
|
|
||||||
|
|
||||||
internal AgentEntity(Guid agentGuid) {
|
internal AgentEntity(Guid agentGuid) {
|
||||||
AgentGuid = agentGuid;
|
AgentGuid = agentGuid;
|
||||||
Name = null!;
|
Name = null!;
|
||||||
|
|||||||
@@ -14,21 +14,15 @@ public abstract class AbstractUpsertHelper<T> where T : class {
|
|||||||
private protected abstract T Construct(Guid guid);
|
private protected abstract T Construct(Guid guid);
|
||||||
|
|
||||||
public T Fetch(Guid guid) {
|
public T Fetch(Guid guid) {
|
||||||
return Fetch(guid, out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Fetch(Guid guid, out bool wasCreated) {
|
|
||||||
DbSet<T> set = Set;
|
DbSet<T> set = Set;
|
||||||
T? entity = set.Find(guid);
|
T? entity = set.Find(guid);
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
entity = Construct(guid);
|
entity = Construct(guid);
|
||||||
set.Add(entity);
|
set.Add(entity);
|
||||||
wasCreated = true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set.Update(entity);
|
set.Update(entity);
|
||||||
wasCreated = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
|
|||||||
@@ -150,12 +150,12 @@ sealed class MinecraftVersionApi : IDisposable {
|
|||||||
|
|
||||||
private static JsonElement GetJsonPropertyOrThrow(JsonElement parentElement, string propertyKey, JsonValueKind expectedKind, string location) {
|
private static JsonElement GetJsonPropertyOrThrow(JsonElement parentElement, string propertyKey, JsonValueKind expectedKind, string location) {
|
||||||
if (!parentElement.TryGetProperty(propertyKey, out var valueElement)) {
|
if (!parentElement.TryGetProperty(propertyKey, out var valueElement)) {
|
||||||
Logger.Error("Missing \"{Property}\" key in {Location}.", propertyKey, location);
|
Logger.Error("Missing \"{Property}\" key in " + location + ".", propertyKey);
|
||||||
throw StopProcedureException.Instance;
|
throw StopProcedureException.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueElement.ValueKind != expectedKind) {
|
if (valueElement.ValueKind != expectedKind) {
|
||||||
Logger.Error("The \"{Property}\" key in {Location} does not contain a JSON {ExpectedType}. Actual type: {ActualType}", propertyKey, location, expectedKind, valueElement.ValueKind);
|
Logger.Error("The \"{Property}\" key in " + location + " does not contain a JSON {ExpectedType}. Actual type: {ActualType}", propertyKey, expectedKind, valueElement.ValueKind);
|
||||||
throw StopProcedureException.Instance;
|
throw StopProcedureException.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
private static readonly TimeSpan DisconnectionThreshold = TimeSpan.FromSeconds(12);
|
private static readonly TimeSpan DisconnectionThreshold = TimeSpan.FromSeconds(12);
|
||||||
|
|
||||||
public readonly record struct Init(
|
public readonly record struct Init(
|
||||||
Guid? LoggedInUserGuid,
|
|
||||||
Guid AgentGuid,
|
Guid AgentGuid,
|
||||||
AgentConfiguration AgentConfiguration,
|
AgentConfiguration AgentConfiguration,
|
||||||
AuthSecret AuthSecret,
|
AuthSecret AuthSecret,
|
||||||
@@ -108,10 +107,6 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
|
|
||||||
this.databaseStorageActor = Context.ActorOf(AgentDatabaseStorageActor.Factory(new AgentDatabaseStorageActor.Init(agentGuid, init.DbProvider, init.CancellationToken)), "DatabaseStorage");
|
this.databaseStorageActor = Context.ActorOf(AgentDatabaseStorageActor.Factory(new AgentDatabaseStorageActor.Init(agentGuid, init.DbProvider, init.CancellationToken)), "DatabaseStorage");
|
||||||
|
|
||||||
if (init.LoggedInUserGuid is {} loggedInUserGuid) {
|
|
||||||
databaseStorageActor.Tell(new AgentDatabaseStorageActor.StoreAgentConfigurationCommand(loggedInUserGuid, configuration));
|
|
||||||
}
|
|
||||||
|
|
||||||
NotifyAgentUpdated();
|
NotifyAgentUpdated();
|
||||||
|
|
||||||
ReceiveAsync<InitializeCommand>(Initialize);
|
ReceiveAsync<InitializeCommand>(Initialize);
|
||||||
@@ -275,7 +270,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
|
|
||||||
Logger.Information("Registered agent \"{AgentName}\" (GUID {AgentGuid}).", AgentName, agentGuid);
|
Logger.Information("Registered agent \"{AgentName}\" (GUID {AgentGuid}).", AgentName, agentGuid);
|
||||||
|
|
||||||
databaseStorageActor.Tell(new AgentDatabaseStorageActor.StoreAgentRuntimeInfoCommand(runtimeInfo));
|
databaseStorageActor.Tell(new AgentDatabaseStorageActor.StoreAgentDataCommand(configuration, authInfo.Secret, runtimeInfo));
|
||||||
|
|
||||||
javaRuntimes = command.JavaRuntimes;
|
javaRuntimes = command.JavaRuntimes;
|
||||||
controllerState.UpdateAgentJavaRuntimes(agentGuid, javaRuntimes);
|
controllerState.UpdateAgentJavaRuntimes(agentGuid, javaRuntimes);
|
||||||
@@ -369,15 +364,19 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
|
|||||||
var isCreating = command.IsCreatingInstance;
|
var isCreating = command.IsCreatingInstance;
|
||||||
|
|
||||||
if (result.Is(ConfigureInstanceResult.Success)) {
|
if (result.Is(ConfigureInstanceResult.Success)) {
|
||||||
string action = isCreating ? "Created" : "Edited";
|
string action = isCreating ? "Added" : "Edited";
|
||||||
Logger.Information(action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) in agent \"{AgentName}\".", instanceName, instanceGuid, AgentName);
|
string relation = isCreating ? "to agent" : "in agent";
|
||||||
|
|
||||||
|
Logger.Information(action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) " + relation + " \"{AgentName}\".", instanceName, instanceGuid, AgentName);
|
||||||
|
|
||||||
return CreateOrUpdateInstanceResult.Success;
|
return CreateOrUpdateInstanceResult.Success;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
string action = isCreating ? "creating" : "editing";
|
string action = isCreating ? "adding" : "editing";
|
||||||
|
string relation = isCreating ? "to agent" : "in agent";
|
||||||
string reason = result.Into(ConfigureInstanceResultExtensions.ToSentence, InstanceActionFailureExtensions.ToSentence);
|
string reason = result.Into(ConfigureInstanceResultExtensions.ToSentence, InstanceActionFailureExtensions.ToSentence);
|
||||||
Logger.Information("Failed " + action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) in agent \"{AgentName}\". {ErrorMessage}", instanceName, instanceGuid, AgentName, reason);
|
|
||||||
|
Logger.Information("Failed " + action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) " + relation + " \"{AgentName}\". {ErrorMessage}", instanceName, instanceGuid, AgentName, reason);
|
||||||
|
|
||||||
return CreateOrUpdateInstanceResult.UnknownError;
|
return CreateOrUpdateInstanceResult.UnknownError;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,16 +25,17 @@ sealed class AgentDatabaseStorageActor : ReceiveActor<AgentDatabaseStorageActor.
|
|||||||
private readonly IDbContextProvider dbProvider;
|
private readonly IDbContextProvider dbProvider;
|
||||||
private readonly CancellationToken cancellationToken;
|
private readonly CancellationToken cancellationToken;
|
||||||
|
|
||||||
private StoreAgentRuntimeInfoCommand? storeRuntimeInfoCommand;
|
private StoreAgentDataCommand? storeCommand;
|
||||||
|
private bool hasScheduledFlush;
|
||||||
|
|
||||||
private AgentDatabaseStorageActor(Init init) {
|
private AgentDatabaseStorageActor(Init init) {
|
||||||
this.agentGuid = init.AgentGuid;
|
this.agentGuid = init.AgentGuid;
|
||||||
this.dbProvider = init.DbProvider;
|
this.dbProvider = init.DbProvider;
|
||||||
this.cancellationToken = init.CancellationToken;
|
this.cancellationToken = init.CancellationToken;
|
||||||
|
|
||||||
Receive<StoreAgentRuntimeInfoCommand>(StoreAgentRuntimeInfo);
|
Receive<StoreAgentDataCommand>(StoreAgentData);
|
||||||
|
ReceiveAsync<FlushAgentDataCommand>(FlushAgentData);
|
||||||
ReceiveAsync<StoreAgentConfigurationCommand>(StoreAgentConfiguration);
|
ReceiveAsync<StoreAgentConfigurationCommand>(StoreAgentConfiguration);
|
||||||
ReceiveAsync<FlushAgentRuntimeInfoCommand>(FlushAgentRuntimeInfo);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ValueTask<AgentEntity?> FindAgentEntity(ILazyDbContext db) {
|
private ValueTask<AgentEntity?> FindAgentEntity(ILazyDbContext db) {
|
||||||
@@ -43,87 +44,71 @@ sealed class AgentDatabaseStorageActor : ReceiveActor<AgentDatabaseStorageActor.
|
|||||||
|
|
||||||
public interface ICommand;
|
public interface ICommand;
|
||||||
|
|
||||||
|
public sealed record StoreAgentDataCommand(AgentConfiguration Configuration, AuthSecret AuthSecret, AgentRuntimeInfo RuntimeInfo) : ICommand;
|
||||||
|
|
||||||
|
private sealed record FlushAgentDataCommand : ICommand;
|
||||||
|
|
||||||
public sealed record StoreAgentConfigurationCommand(Guid AuditLogUserGuid, AgentConfiguration Configuration) : ICommand;
|
public sealed record StoreAgentConfigurationCommand(Guid AuditLogUserGuid, AgentConfiguration Configuration) : ICommand;
|
||||||
|
|
||||||
public sealed record StoreAgentRuntimeInfoCommand(AgentRuntimeInfo RuntimeInfo) : ICommand;
|
private void StoreAgentData(StoreAgentDataCommand command) {
|
||||||
|
storeCommand = command;
|
||||||
private sealed record FlushAgentRuntimeInfoCommand : ICommand;
|
|
||||||
|
|
||||||
private async Task StoreAgentConfiguration(StoreAgentConfigurationCommand command) {
|
|
||||||
await FlushAgentRuntimeInfo();
|
|
||||||
|
|
||||||
bool wasCreated;
|
|
||||||
|
|
||||||
await using (var db = dbProvider.Lazy()) {
|
|
||||||
var entity = db.Ctx.AgentUpsert.Fetch(agentGuid, out wasCreated);
|
|
||||||
|
|
||||||
if (wasCreated) {
|
|
||||||
entity.AuthSecret = AuthSecret.Generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
entity.Name = command.Configuration.AgentName;
|
|
||||||
|
|
||||||
var auditLogWriter = new AuditLogRepository(db).Writer(command.AuditLogUserGuid);
|
|
||||||
if (wasCreated) {
|
|
||||||
auditLogWriter.AgentCreated(agentGuid);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
auditLogWriter.AgentEdited(agentGuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.Ctx.SaveChangesAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
string action = wasCreated ? "Created" : "Edited";
|
|
||||||
Logger.Information(action + " agent \"{AgentName}\" (GUID {AgentGuid}) in database.", command.Configuration.AgentName, agentGuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StoreAgentRuntimeInfo(StoreAgentRuntimeInfoCommand command) {
|
|
||||||
storeRuntimeInfoCommand = command;
|
|
||||||
ScheduleFlush(TimeSpan.FromSeconds(2));
|
ScheduleFlush(TimeSpan.FromSeconds(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScheduleFlush(TimeSpan delay) {
|
private void ScheduleFlush(TimeSpan delay) {
|
||||||
if (storeRuntimeInfoCommand != null) {
|
if (!hasScheduledFlush) {
|
||||||
Timers.StartSingleTimer("FlushChanges", new FlushAgentRuntimeInfoCommand(), delay, Self);
|
hasScheduledFlush = true;
|
||||||
|
Timers.StartSingleTimer("FlushChanges", new FlushAgentDataCommand(), delay, Self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task FlushAgentRuntimeInfo(FlushAgentRuntimeInfoCommand command) {
|
private Task FlushAgentData(FlushAgentDataCommand command) {
|
||||||
return FlushAgentRuntimeInfo();
|
return FlushAgentData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task FlushAgentRuntimeInfo() {
|
private async Task FlushAgentData() {
|
||||||
if (storeRuntimeInfoCommand == null) {
|
hasScheduledFlush = false;
|
||||||
|
|
||||||
|
if (storeCommand == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string agentName;
|
|
||||||
|
|
||||||
await using (var db = dbProvider.Lazy()) {
|
|
||||||
var entity = await FindAgentEntity(db);
|
|
||||||
if (entity == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
agentName = entity.Name;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
entity.ProtocolVersion = storeRuntimeInfoCommand.RuntimeInfo.VersionInfo?.ProtocolVersion;
|
await using var ctx = dbProvider.Eager();
|
||||||
entity.BuildVersion = storeRuntimeInfoCommand.RuntimeInfo.VersionInfo?.BuildVersion;
|
var entity = ctx.AgentUpsert.Fetch(agentGuid);
|
||||||
entity.MaxInstances = storeRuntimeInfoCommand.RuntimeInfo.MaxInstances;
|
|
||||||
entity.MaxMemory = storeRuntimeInfoCommand.RuntimeInfo.MaxMemory;
|
|
||||||
|
|
||||||
await db.Ctx.SaveChangesAsync(cancellationToken);
|
entity.Name = storeCommand.Configuration.AgentName;
|
||||||
|
entity.ProtocolVersion = storeCommand.RuntimeInfo.ProtocolVersion;
|
||||||
|
entity.BuildVersion = storeCommand.RuntimeInfo.BuildVersion;
|
||||||
|
entity.MaxInstances = storeCommand.RuntimeInfo.MaxInstances;
|
||||||
|
entity.MaxMemory = storeCommand.RuntimeInfo.MaxMemory;
|
||||||
|
entity.AuthSecret = storeCommand.AuthSecret;
|
||||||
|
|
||||||
|
await ctx.SaveChangesAsync(cancellationToken);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ScheduleFlush(TimeSpan.FromSeconds(10));
|
ScheduleFlush(TimeSpan.FromSeconds(10));
|
||||||
Logger.Error(e, "Could not update agent \"{AgentName}\" (GUID {AgentGuid}) in database.", entity.Name, agentGuid);
|
Logger.Error(e, "Could not store agent \"{AgentName}\" (GUID {AgentGuid}) in database.", storeCommand.Configuration.AgentName, agentGuid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.Information("Stored agent \"{AgentName}\" (GUID {AgentGuid}) in database.", storeCommand.Configuration.AgentName, agentGuid);
|
||||||
|
|
||||||
|
storeCommand = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.Information("Updated agent \"{AgentName}\" (GUID {AgentGuid}) in database.", agentName, agentGuid);
|
private async Task StoreAgentConfiguration(StoreAgentConfigurationCommand command) {
|
||||||
|
await FlushAgentData();
|
||||||
|
|
||||||
storeRuntimeInfoCommand = null;
|
await using var db = dbProvider.Lazy();
|
||||||
|
|
||||||
|
var entity = await FindAgentEntity(db);
|
||||||
|
if (entity != null) {
|
||||||
|
entity.Name = command.Configuration.AgentName;
|
||||||
|
}
|
||||||
|
|
||||||
|
var auditLogWriter = new AuditLogRepository(db).Writer(command.AuditLogUserGuid);
|
||||||
|
auditLogWriter.AgentEdited(agentGuid);
|
||||||
|
|
||||||
|
await db.Ctx.SaveChangesAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,15 +37,17 @@ sealed class AgentManager(
|
|||||||
|
|
||||||
await foreach (var entity in ctx.Agents.AsAsyncEnumerable().WithCancellation(cancellationToken)) {
|
await foreach (var entity in ctx.Agents.AsAsyncEnumerable().WithCancellation(cancellationToken)) {
|
||||||
var agentGuid = entity.AgentGuid;
|
var agentGuid = entity.AgentGuid;
|
||||||
|
var configuration = new AgentConfiguration(entity.Name);
|
||||||
|
var runtimeInfo = new AgentRuntimeInfo(entity.ProtocolVersion, entity.BuildVersion, entity.MaxInstances, entity.MaxMemory);
|
||||||
|
|
||||||
if (AddAgent(loggedInUserGuid: null, agentGuid, entity.Configuration, entity.AuthSecret!, entity.RuntimeInfo)) {
|
if (AddAgent(agentGuid, configuration, entity.AuthSecret!, runtimeInfo)) {
|
||||||
Logger.Information("Loaded agent \"{AgentName}\" (GUID {AgentGuid}) from database.", entity.Name, agentGuid);
|
Logger.Information("Loaded agent \"{AgentName}\" (GUID {AgentGuid}) from database.", entity.Name, agentGuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool AddAgent(Guid? loggedInUserGuid, Guid agentGuid, AgentConfiguration configuration, AuthSecret authSecret, AgentRuntimeInfo runtimeInfo) {
|
private bool AddAgent(Guid agentGuid, AgentConfiguration configuration, AuthSecret authSecret, AgentRuntimeInfo runtimeInfo) {
|
||||||
var init = new AgentActor.Init(loggedInUserGuid, agentGuid, configuration, authSecret, runtimeInfo, agentConnectionKeys, controllerState, minecraftVersions, dbProvider, cancellationToken);
|
var init = new AgentActor.Init(agentGuid, configuration, authSecret, runtimeInfo, agentConnectionKeys, controllerState, minecraftVersions, dbProvider, cancellationToken);
|
||||||
var name = "Agent:" + agentGuid;
|
var name = "Agent:" + agentGuid;
|
||||||
return agentsByAgentGuid.TryAdd(agentGuid, actorSystem.ActorOf(AgentActor.Factory(init), name));
|
return agentsByAgentGuid.TryAdd(agentGuid, actorSystem.ActorOf(AgentActor.Factory(init), name));
|
||||||
}
|
}
|
||||||
@@ -87,31 +89,13 @@ sealed class AgentManager(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.Warning("Could not deliver command {CommandType} to unknown agent {AgentGuid}.", command.GetType().Name, agentGuid);
|
Logger.Warning("Could not deliver command {CommandType} to non-existent agent {AgentGuid}.", command.GetType().Name, agentGuid);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<CreateOrUpdateAgentResult, UserActionFailure> CreateOrUpdateAgent(LoggedInUser loggedInUser, Guid agentGuid, AgentConfiguration configuration) {
|
public async Task<Result<TReply, UserInstanceActionFailure>> DoInstanceAction<TCommand, TReply>(Permission requiredPermission, ImmutableArray<byte> authToken, Guid agentGuid, Func<Guid, TCommand> commandFactoryFromLoggedInUserGuid) where TCommand : class, AgentActor.ICommand, ICanReply<Result<TReply, InstanceActionFailure>> {
|
||||||
if (!loggedInUser.CheckPermission(Permission.ManageAllAgents)) {
|
var loggedInUser = userLoginManager.GetLoggedInUser(authToken);
|
||||||
return UserActionFailure.NotAuthorized;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (configuration.AgentName.Length == 0) {
|
|
||||||
return CreateOrUpdateAgentResult.AgentNameMustNotBeEmpty;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (agentsByAgentGuid.TryGetValue(agentGuid, out var agent)) {
|
|
||||||
agent.Tell(new AgentActor.ConfigureAgentCommand(loggedInUser.Guid!.Value, configuration));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
AddAgent(loggedInUser.Guid!.Value, agentGuid, configuration, AuthSecret.Generate(), new AgentRuntimeInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
return CreateOrUpdateAgentResult.Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Result<TReply, UserInstanceActionFailure>> DoInstanceAction<TCommand, TReply>(LoggedInUser loggedInUser, Permission requiredPermission, Guid agentGuid, Func<Guid, TCommand> commandFactoryFromLoggedInUserGuid) where TCommand : class, AgentActor.ICommand, ICanReply<Result<TReply, InstanceActionFailure>> {
|
|
||||||
if (!loggedInUser.HasAccessToAgent(agentGuid) || !loggedInUser.CheckPermission(requiredPermission)) {
|
if (!loggedInUser.HasAccessToAgent(agentGuid) || !loggedInUser.CheckPermission(requiredPermission)) {
|
||||||
return (UserInstanceActionFailure) UserActionFailure.NotAuthorized;
|
return (UserInstanceActionFailure) UserActionFailure.NotAuthorized;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ sealed class WebMessageHandlerActor : ReceiveActor<IMessageToController> {
|
|||||||
ReceiveAndReplyLater<GetUserRolesMessage, ImmutableDictionary<Guid, ImmutableArray<Guid>>>(GetUserRoles);
|
ReceiveAndReplyLater<GetUserRolesMessage, ImmutableDictionary<Guid, ImmutableArray<Guid>>>(GetUserRoles);
|
||||||
ReceiveAndReplyLater<ChangeUserRolesMessage, Result<ChangeUserRolesResult, UserActionFailure>>(ChangeUserRoles);
|
ReceiveAndReplyLater<ChangeUserRolesMessage, Result<ChangeUserRolesResult, UserActionFailure>>(ChangeUserRoles);
|
||||||
ReceiveAndReplyLater<DeleteUserMessage, Result<DeleteUserResult, UserActionFailure>>(DeleteUser);
|
ReceiveAndReplyLater<DeleteUserMessage, Result<DeleteUserResult, UserActionFailure>>(DeleteUser);
|
||||||
ReceiveAndReply<CreateOrUpdateAgentMessage, Result<CreateOrUpdateAgentResult, UserActionFailure>>(CreateOrUpdateAgentMessage);
|
ReceiveAndReplyLater<CreateOrUpdateAgentMessage, Result<CreateOrUpdateAgentResult, UserActionFailure>>(CreateOrUpdateAgentMessage);
|
||||||
ReceiveAndReply<GetAgentJavaRuntimesMessage, ImmutableDictionary<Guid, ImmutableArray<TaggedJavaRuntime>>>(GetAgentJavaRuntimes);
|
ReceiveAndReply<GetAgentJavaRuntimesMessage, ImmutableDictionary<Guid, ImmutableArray<TaggedJavaRuntime>>>(GetAgentJavaRuntimes);
|
||||||
ReceiveAndReplyLater<CreateOrUpdateInstanceMessage, Result<CreateOrUpdateInstanceResult, UserInstanceActionFailure>>(CreateOrUpdateInstance);
|
ReceiveAndReplyLater<CreateOrUpdateInstanceMessage, Result<CreateOrUpdateInstanceResult, UserInstanceActionFailure>>(CreateOrUpdateInstance);
|
||||||
ReceiveAndReplyLater<LaunchInstanceMessage, Result<LaunchInstanceResult, UserInstanceActionFailure>>(LaunchInstance);
|
ReceiveAndReplyLater<LaunchInstanceMessage, Result<LaunchInstanceResult, UserInstanceActionFailure>>(LaunchInstance);
|
||||||
@@ -125,7 +125,7 @@ sealed class WebMessageHandlerActor : ReceiveActor<IMessageToController> {
|
|||||||
return userManager.DeleteByGuid(userLoginManager.GetLoggedInUser(message.AuthToken), message.SubjectUserGuid);
|
return userManager.DeleteByGuid(userLoginManager.GetLoggedInUser(message.AuthToken), message.SubjectUserGuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result<CreateOrUpdateAgentResult, UserActionFailure> CreateOrUpdateAgentMessage(CreateOrUpdateAgentMessage message) {
|
private Task<Result<CreateOrUpdateAgentResult, UserActionFailure>> CreateOrUpdateAgentMessage(CreateOrUpdateAgentMessage message) {
|
||||||
return agentManager.CreateOrUpdateAgent(userLoginManager.GetLoggedInUser(message.AuthToken), message.AgentGuid, message.Configuration);
|
return agentManager.CreateOrUpdateAgent(userLoginManager.GetLoggedInUser(message.AuthToken), message.AgentGuid, message.Configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ Use volumes to persist either the whole `/data` folder, or just `/data/data` if
|
|||||||
* **Controller Communication**
|
* **Controller Communication**
|
||||||
- `CONTROLLER_HOST` is the hostname of the Controller.
|
- `CONTROLLER_HOST` is the hostname of the Controller.
|
||||||
- `CONTROLLER_PORT` is the Agent RPC port of the Controller. Default: `9401`
|
- `CONTROLLER_PORT` is the Agent RPC port of the Controller. Default: `9401`
|
||||||
- `AGENT_KEY` is the [Agent Key](#secrets). Mutually exclusive with `AGENT_KEY_FILE`.
|
- `AGENT_KEY` is the [Agent Key](#agent--web-keys). Mutually exclusive with `AGENT_KEY_FILE`.
|
||||||
- `AGENT_KEY_FILE` is a path to a file containing the [Agent Key](#secrets). Mutually exclusive with `AGENT_KEY`.
|
- `AGENT_KEY_FILE` is a path to a file containing the [Agent Key](#agent--web-keys). Mutually exclusive with `AGENT_KEY`.
|
||||||
* **Agent Configuration**
|
* **Agent Configuration**
|
||||||
- `MAX_INSTANCES` is the number of instances that can be created.
|
- `MAX_INSTANCES` is the number of instances that can be created.
|
||||||
- `MAX_MEMORY` is the maximum amount of RAM that can be distributed among all instances. Use a positive integer with an optional suffix 'M' for MB, or 'G' for GB. Examples: `4096M`, `16G`
|
- `MAX_MEMORY` is the maximum amount of RAM that can be distributed among all instances. Use a positive integer with an optional suffix 'M' for MB, or 'G' for GB. Examples: `4096M`, `16G`
|
||||||
@@ -110,8 +110,8 @@ Use volumes to persist the whole `/data` folder.
|
|||||||
* **Controller Communication**
|
* **Controller Communication**
|
||||||
- `CONTROLLER_HOST` is the hostname of the Controller.
|
- `CONTROLLER_HOST` is the hostname of the Controller.
|
||||||
- `CONTROLLER_PORT` is the Web RPC port of the Controller. Default: `9402`
|
- `CONTROLLER_PORT` is the Web RPC port of the Controller. Default: `9402`
|
||||||
- `WEB_KEY` is the [Web Key](#secrets). Mutually exclusive with `WEB_KEY_FILE`.
|
- `WEB_KEY` is the [Web Key](#agent--web-keys). Mutually exclusive with `WEB_KEY_FILE`.
|
||||||
- `WEB_KEY_FILE` is a path to a file containing the [Web Key](#secrets). Mutually exclusive with `WEB_KEY`.
|
- `WEB_KEY_FILE` is a path to a file containing the [Web Key](#agent--web-keys). Mutually exclusive with `WEB_KEY`.
|
||||||
* **Web Server**
|
* **Web Server**
|
||||||
- `WEB_SERVER_HOST` is the host. Default: `0.0.0.0`
|
- `WEB_SERVER_HOST` is the host. Default: `0.0.0.0`
|
||||||
- `WEB_SERVER_PORT` is the port. Default: `9400`
|
- `WEB_SERVER_PORT` is the port. Default: `9400`
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="progress-label">@ChildContent</div>
|
<div class="progress-label">@ChildContent</div>
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
<div class="progress-bar" role="progressbar" style="width: @(Maximum <= 0 ? 0 : 100 * Value / Maximum)%;" aria-valuenow="@Value" aria-valuemin="0" aria-valuemax="@Maximum"></div>
|
<div class="progress-bar" role="progressbar" style="width: @(100 * Value / Maximum)%;" aria-valuenow="@Value" aria-valuemin="0" aria-valuemax="@Maximum"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -37,37 +37,35 @@
|
|||||||
<small class="font-monospace text-uppercase">@agent.AgentGuid.ToString()</small>
|
<small class="font-monospace text-uppercase">@agent.AgentGuid.ToString()</small>
|
||||||
</Cell>
|
</Cell>
|
||||||
<Cell class="text-end">
|
<Cell class="text-end">
|
||||||
<ProgressBar Value="@(usedInstances ?? 0)" Maximum="@(runtimeInfo.MaxInstances ?? 0)">
|
@if (runtimeInfo == null) {
|
||||||
@if (runtimeInfo.MaxInstances is {} maxInstances) {
|
<text>N/A</text>
|
||||||
<text>@(usedInstances?.ToString() ?? "?") / @maxInstances.ToString()</text>
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@:N/A
|
<ProgressBar Value="@(usedInstances ?? 0)" Maximum="@runtimeInfo.MaxInstances">
|
||||||
}
|
@(usedInstances?.ToString() ?? "?") / @runtimeInfo.MaxInstances.ToString()
|
||||||
</ProgressBar>
|
</ProgressBar>
|
||||||
|
}
|
||||||
</Cell>
|
</Cell>
|
||||||
<Cell class="text-end">
|
<Cell class="text-end">
|
||||||
<ProgressBar Value="@(usedMemory ?? 0)" Maximum="@(runtimeInfo.MaxMemory?.InMegabytes ?? 0)">
|
@if (runtimeInfo == null) {
|
||||||
@if (runtimeInfo.MaxMemory is {} maxMemory) {
|
<text>N/A</text>
|
||||||
<text>@(usedMemory?.ToString() ?? "?") / @maxMemory.InMegabytes MB</text>
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@:N/A
|
<ProgressBar Value="@(usedMemory ?? 0)" Maximum="@runtimeInfo.MaxMemory.InMegabytes">
|
||||||
}
|
@(usedMemory?.ToString() ?? "?") / @runtimeInfo.MaxMemory.InMegabytes.ToString() MB
|
||||||
</ProgressBar>
|
</ProgressBar>
|
||||||
|
}
|
||||||
</Cell>
|
</Cell>
|
||||||
@if (runtimeInfo.VersionInfo is {} versionInfo) {
|
|
||||||
<Cell class="text-condensed">
|
<Cell class="text-condensed">
|
||||||
Build: <span class="font-monospace">@versionInfo.BuildVersion</span>
|
@if (runtimeInfo == null) {
|
||||||
<br>
|
<text>N/A</text>
|
||||||
Protocol: <span class="font-monospace">v@(versionInfo.ProtocolVersion.ToString())</span>
|
|
||||||
</Cell>
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
<Cell>
|
<text>Build: <span class="font-monospace">@runtimeInfo.BuildVersion</span></text>
|
||||||
N/A
|
<br>
|
||||||
</Cell>
|
<text>Protocol: <span class="font-monospace">v@(runtimeInfo.ProtocolVersion.ToString())</span></text>
|
||||||
}
|
}
|
||||||
|
</Cell>
|
||||||
@switch (agent.ConnectionStatus) {
|
@switch (agent.ConnectionStatus) {
|
||||||
case AgentIsOnline:
|
case AgentIsOnline:
|
||||||
<Cell class="fw-semibold text-center text-success">Online</Cell>
|
<Cell class="fw-semibold text-center text-success">Online</Cell>
|
||||||
@@ -91,10 +89,7 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
<Cell>
|
<Cell>
|
||||||
<PermissionView Permission="Permission.ManageAllAgents">
|
|
||||||
<a href="agents/@agent.AgentGuid/edit" type="button" class="btn btn-primary btn-sm">Edit Agent</a>
|
|
||||||
<button type="button" class="btn btn-danger btn-sm" data-clipboard="@connectionKey" onclick="copyToClipboard(this);">Copy Agent Key</button>
|
<button type="button" class="btn btn-danger btn-sm" data-clipboard="@connectionKey" onclick="copyToClipboard(this);">Copy Agent Key</button>
|
||||||
</PermissionView>
|
|
||||||
</Cell>
|
</Cell>
|
||||||
</ItemRow>
|
</ItemRow>
|
||||||
<NoItemsRow>
|
<NoItemsRow>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<Form Model="form" OnSubmit="AddOrEditAgent">
|
<Form Model="form" OnSubmit="AddOrEditAgent">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-12 mb-3">
|
<div class="col-xl-5 mb-3">
|
||||||
<FormTextInput Id="agent-name" Label="Agent Name" @bind-Value="form.AgentName" />
|
<FormTextInput Id="agent-name" Label="Agent Name" @bind-Value="form.AgentName" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -31,17 +31,13 @@
|
|||||||
static RenderFragment GetAgentOption(Agent agent) {
|
static RenderFragment GetAgentOption(Agent agent) {
|
||||||
var runtimeInfo = agent.RuntimeInfo;
|
var runtimeInfo = agent.RuntimeInfo;
|
||||||
return
|
return
|
||||||
@<option value="@agent.AgentGuid" disabled="@(agent.ConnectionStatus is not AgentIsOnline)">
|
@<option value="@agent.AgentGuid">
|
||||||
@agent.Configuration.AgentName
|
@agent.Configuration.AgentName
|
||||||
@if (agent.ConnectionStatus is not AgentIsOnline) {
|
@if (runtimeInfo != null) {
|
||||||
<text> • </text>
|
|
||||||
<text>Offline</text>
|
|
||||||
}
|
|
||||||
else if (runtimeInfo.MaxInstances is not null && runtimeInfo.MaxMemory is not null) {
|
|
||||||
<text>•</text>
|
<text>•</text>
|
||||||
<text>@(agent.Stats?.RunningInstanceCount.ToString() ?? "?")/@(runtimeInfo.MaxInstances) @(runtimeInfo.MaxInstances == 1 ? "Instance" : "Instances")</text>
|
<text>@(agent.Stats?.RunningInstanceCount.ToString() ?? "?")/@(runtimeInfo.MaxInstances) @(runtimeInfo.MaxInstances == 1 ? "Instance" : "Instances")</text>
|
||||||
<text>•</text>
|
<text>•</text>
|
||||||
<text>@(agent.Stats?.RunningInstanceMemory.InMegabytes.ToString() ?? "?")/@(runtimeInfo.MaxMemory.Value.InMegabytes) MB RAM</text>
|
<text>@(agent.Stats?.RunningInstanceMemory.InMegabytes.ToString() ?? "?")/@(runtimeInfo.MaxMemory.InMegabytes) MB RAM</text>
|
||||||
}
|
}
|
||||||
</option>;
|
</option>;
|
||||||
}
|
}
|
||||||
@@ -49,7 +45,7 @@
|
|||||||
@if (EditedInstance == null) {
|
@if (EditedInstance == null) {
|
||||||
<FormSelectInput Id="instance-agent" Label="Agent" @bind-Value="form.SelectedAgentGuid">
|
<FormSelectInput Id="instance-agent" Label="Agent" @bind-Value="form.SelectedAgentGuid">
|
||||||
<option value="" selected>Select which agent will run the instance...</option>
|
<option value="" selected>Select which agent will run the instance...</option>
|
||||||
@foreach (var agent in allAgentsByGuid.Values.OrderBy(static agent => agent.Configuration.AgentName)) {
|
@foreach (var agent in allAgentsByGuid.Values.Where(static agent => agent.ConnectionStatus is AgentIsOnline).OrderBy(static agent => agent.Configuration.AgentName)) {
|
||||||
@GetAgentOption(agent)
|
@GetAgentOption(agent)
|
||||||
}
|
}
|
||||||
</FormSelectInput>
|
</FormSelectInput>
|
||||||
@@ -107,8 +103,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
@{
|
@{
|
||||||
string? allowedServerPorts = selectedAgent?.RuntimeInfo.AllowedServerPorts?.ToString();
|
string? allowedServerPorts = selectedAgent?.RuntimeInfo?.AllowedServerPorts?.ToString();
|
||||||
string? allowedRconPorts = selectedAgent?.RuntimeInfo.AllowedRconPorts?.ToString();
|
string? allowedRconPorts = selectedAgent?.RuntimeInfo?.AllowedRconPorts?.ToString();
|
||||||
}
|
}
|
||||||
<div class="col-sm-6 col-xl-2 mb-3">
|
<div class="col-sm-6 col-xl-2 mb-3">
|
||||||
<FormNumberInput Id="instance-server-port" @bind-Value="form.ServerPort" min="0" max="65535">
|
<FormNumberInput Id="instance-server-port" @bind-Value="form.ServerPort" min="0" max="65535">
|
||||||
@@ -147,11 +143,11 @@
|
|||||||
}
|
}
|
||||||
<FormNumberInput Id="instance-memory" Type="FormNumberInputType.Range" DebounceMillis="0" DisableTwoWayBinding="true" @bind-Value="form.MemoryUnits" min="@MinimumMemoryUnits" max="@maximumMemoryUnits" disabled="@(maximumMemoryUnits == 0)" class="form-range split-danger" style="@memoryInputSplitVar">
|
<FormNumberInput Id="instance-memory" Type="FormNumberInputType.Range" DebounceMillis="0" DisableTwoWayBinding="true" @bind-Value="form.MemoryUnits" min="@MinimumMemoryUnits" max="@maximumMemoryUnits" disabled="@(maximumMemoryUnits == 0)" class="form-range split-danger" style="@memoryInputSplitVar">
|
||||||
<LabelFragment>
|
<LabelFragment>
|
||||||
@if (maximumMemoryUnits == 0 || selectedAgent?.RuntimeInfo.MaxMemory is not {} maxMemory) {
|
@if (maximumMemoryUnits == 0 || selectedAgent?.RuntimeInfo == null) {
|
||||||
<text>RAM</text>
|
<text>RAM</text>
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
<text>RAM • <code>@(form.MemoryAllocation?.InMegabytes ?? 0) / @(maxMemory.InMegabytes) MB</code></text>
|
<text>RAM • <code>@(form.MemoryAllocation?.InMegabytes ?? 0) / @(selectedAgent.RuntimeInfo.MaxMemory.InMegabytes) MB</code></text>
|
||||||
}
|
}
|
||||||
</LabelFragment>
|
</LabelFragment>
|
||||||
</FormNumberInput>
|
</FormNumberInput>
|
||||||
@@ -215,7 +211,7 @@
|
|||||||
|
|
||||||
public ImmutableArray<TaggedJavaRuntime> JavaRuntimesForSelectedAgent => TryGet(page.allAgentJavaRuntimes, SelectedAgentGuid, out var javaRuntimes) ? javaRuntimes : ImmutableArray<TaggedJavaRuntime>.Empty;
|
public ImmutableArray<TaggedJavaRuntime> JavaRuntimesForSelectedAgent => TryGet(page.allAgentJavaRuntimes, SelectedAgentGuid, out var javaRuntimes) ? javaRuntimes : ImmutableArray<TaggedJavaRuntime>.Empty;
|
||||||
|
|
||||||
public ushort MaximumMemoryUnits => SelectedAgent?.RuntimeInfo.MaxMemory?.RawValue ?? 0;
|
public ushort MaximumMemoryUnits => SelectedAgent?.RuntimeInfo?.MaxMemory.RawValue ?? 0;
|
||||||
public ushort AvailableMemoryUnits => Math.Min((SelectedAgent?.AvailableMemory + editedInstanceRamAllocation)?.RawValue ?? MaximumMemoryUnits, MaximumMemoryUnits);
|
public ushort AvailableMemoryUnits => Math.Min((SelectedAgent?.AvailableMemory + editedInstanceRamAllocation)?.RawValue ?? MaximumMemoryUnits, MaximumMemoryUnits);
|
||||||
private ushort selectedMemoryUnits = 4;
|
private ushort selectedMemoryUnits = 4;
|
||||||
|
|
||||||
@@ -256,12 +252,12 @@
|
|||||||
|
|
||||||
public sealed class ServerPortMustBeAllowedAttribute : FormValidationAttribute<ConfigureInstanceFormModel, int> {
|
public sealed class ServerPortMustBeAllowedAttribute : FormValidationAttribute<ConfigureInstanceFormModel, int> {
|
||||||
protected override string FieldName => nameof(ServerPort);
|
protected override string FieldName => nameof(ServerPort);
|
||||||
protected override bool IsValid(ConfigureInstanceFormModel model, int value) => model.SelectedAgent is not {} agent || agent.RuntimeInfo.AllowedServerPorts?.Contains((ushort) value) == true;
|
protected override bool IsValid(ConfigureInstanceFormModel model, int value) => model.SelectedAgent is not {} agent || agent.RuntimeInfo?.AllowedServerPorts?.Contains((ushort) value) == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class RconPortMustBeAllowedAttribute : FormValidationAttribute<ConfigureInstanceFormModel, int> {
|
public sealed class RconPortMustBeAllowedAttribute : FormValidationAttribute<ConfigureInstanceFormModel, int> {
|
||||||
protected override string FieldName => nameof(RconPort);
|
protected override string FieldName => nameof(RconPort);
|
||||||
protected override bool IsValid(ConfigureInstanceFormModel model, int value) => model.SelectedAgent is not {} agent || agent.RuntimeInfo.AllowedRconPorts?.Contains((ushort) value) == true;
|
protected override bool IsValid(ConfigureInstanceFormModel model, int value) => model.SelectedAgent is not {} agent || agent.RuntimeInfo?.AllowedRconPorts?.Contains((ushort) value) == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class RconPortMustDifferFromServerPortAttribute : FormValidationAttribute<ConfigureInstanceFormModel, int?> {
|
public sealed class RconPortMustDifferFromServerPortAttribute : FormValidationAttribute<ConfigureInstanceFormModel, int?> {
|
||||||
|
|||||||
Reference in New Issue
Block a user