1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2026-01-14 05:50:30 +01:00

2 Commits

Author SHA1 Message Date
d63089ead2 WIP 2025-12-28 04:03:24 +01:00
68e0801e4f Fix logging templates 2025-12-28 04:02:38 +01:00
13 changed files with 158 additions and 111 deletions

View File

@@ -43,7 +43,7 @@ sealed record Variables(
try {
return LoadOrThrow();
} catch (Exception e) {
PhantomLogger.Root.Fatal(e.Message);
PhantomLogger.Root.Fatal("{}", e.Message);
throw StopProcedureException.Instance;
}
}

View File

@@ -9,10 +9,10 @@ public sealed partial record Agent(
[property: MemoryPackOrder(0)] Guid AgentGuid,
[property: MemoryPackOrder(1)] AgentConfiguration Configuration,
[property: MemoryPackOrder(2)] ImmutableArray<byte> ConnectionKey,
[property: MemoryPackOrder(3)] AgentRuntimeInfo? RuntimeInfo,
[property: MemoryPackOrder(3)] AgentRuntimeInfo RuntimeInfo,
[property: MemoryPackOrder(4)] AgentStats? Stats,
[property: MemoryPackOrder(5)] IAgentConnectionStatus ConnectionStatus
) {
[MemoryPackIgnore]
public RamAllocationUnits? AvailableMemory => RuntimeInfo?.MaxMemory - Stats?.RunningInstanceMemory;
public RamAllocationUnits? AvailableMemory => RuntimeInfo.MaxMemory - Stats?.RunningInstanceMemory;
}

View File

@@ -5,14 +5,13 @@ namespace Phantom.Common.Data.Web.Agent;
[MemoryPackable(GenerateType.VersionTolerant)]
public sealed partial record AgentRuntimeInfo(
[property: MemoryPackOrder(0)] ushort ProtocolVersion,
[property: MemoryPackOrder(1)] string BuildVersion,
[property: MemoryPackOrder(2)] ushort MaxInstances,
[property: MemoryPackOrder(3)] RamAllocationUnits MaxMemory,
[property: MemoryPackOrder(4)] AllowedPorts? AllowedServerPorts = null,
[property: MemoryPackOrder(5)] AllowedPorts? AllowedRconPorts = null
[property: MemoryPackOrder(0)] AgentVersionInfo? VersionInfo = null,
[property: MemoryPackOrder(1)] ushort? MaxInstances = null,
[property: MemoryPackOrder(2)] RamAllocationUnits? MaxMemory = null,
[property: MemoryPackOrder(3)] AllowedPorts? AllowedServerPorts = null,
[property: MemoryPackOrder(4)] AllowedPorts? AllowedRconPorts = null
) {
public static AgentRuntimeInfo From(AgentInfo agentInfo) {
return new AgentRuntimeInfo(agentInfo.ProtocolVersion, agentInfo.BuildVersion, agentInfo.MaxInstances, agentInfo.MaxMemory, agentInfo.AllowedServerPorts, agentInfo.AllowedRconPorts);
return new AgentRuntimeInfo(new AgentVersionInfo(agentInfo.ProtocolVersion, agentInfo.BuildVersion), agentInfo.MaxInstances, agentInfo.MaxMemory, agentInfo.AllowedServerPorts, agentInfo.AllowedRconPorts);
}
}

View File

@@ -0,0 +1,9 @@
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
);

View File

@@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.CodeAnalysis;
using Phantom.Common.Data;
using Phantom.Common.Data.Web.Agent;
using Phantom.Utils.Rpc;
namespace Phantom.Controller.Database.Entities;
@@ -13,14 +14,18 @@ public sealed class AgentEntity {
public Guid AgentGuid { get; init; }
public string Name { get; set; }
public ushort ProtocolVersion { get; set; }
public string BuildVersion { get; set; }
public ushort MaxInstances { get; set; }
public RamAllocationUnits MaxMemory { get; set; }
public ushort? ProtocolVersion { get; set; }
public string? BuildVersion { get; set; }
public ushort? MaxInstances { get; set; }
public RamAllocationUnits? MaxMemory { get; set; }
[MaxLength(AuthSecret.Length)]
public AuthSecret? AuthSecret { get; set; }
public AgentConfiguration Configuration => new (Name);
public AgentVersionInfo? VersionInfo => ProtocolVersion is null || BuildVersion is null ? null : new AgentVersionInfo(ProtocolVersion, BuildVersion);
public AgentRuntimeInfo RuntimeInfo => new (VersionInfo, MaxInstances, MaxMemory);
internal AgentEntity(Guid agentGuid) {
AgentGuid = agentGuid;
Name = null!;

View File

@@ -14,15 +14,21 @@ public abstract class AbstractUpsertHelper<T> where T : class {
private protected abstract T Construct(Guid guid);
public T Fetch(Guid guid) {
return Fetch(guid, out _);
}
public T Fetch(Guid guid, out bool wasCreated) {
DbSet<T> set = Set;
T? entity = set.Find(guid);
if (entity == null) {
entity = Construct(guid);
set.Add(entity);
wasCreated = true;
}
else {
set.Update(entity);
wasCreated = false;
}
return entity;

View File

@@ -150,12 +150,12 @@ sealed class MinecraftVersionApi : IDisposable {
private static JsonElement GetJsonPropertyOrThrow(JsonElement parentElement, string propertyKey, JsonValueKind expectedKind, string location) {
if (!parentElement.TryGetProperty(propertyKey, out var valueElement)) {
Logger.Error("Missing \"{Property}\" key in " + location + ".", propertyKey);
Logger.Error("Missing \"{Property}\" key in {Location}.", propertyKey, location);
throw StopProcedureException.Instance;
}
if (valueElement.ValueKind != expectedKind) {
Logger.Error("The \"{Property}\" key in " + location + " does not contain a JSON {ExpectedType}. Actual type: {ActualType}", propertyKey, expectedKind, valueElement.ValueKind);
Logger.Error("The \"{Property}\" key in {Location} does not contain a JSON {ExpectedType}. Actual type: {ActualType}", propertyKey, location, expectedKind, valueElement.ValueKind);
throw StopProcedureException.Instance;
}

View File

@@ -34,6 +34,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
private static readonly TimeSpan DisconnectionThreshold = TimeSpan.FromSeconds(12);
public readonly record struct Init(
Guid? LoggedInUserGuid,
Guid AgentGuid,
AgentConfiguration AgentConfiguration,
AuthSecret AuthSecret,
@@ -107,6 +108,10 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
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();
ReceiveAsync<InitializeCommand>(Initialize);
@@ -270,7 +275,7 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
Logger.Information("Registered agent \"{AgentName}\" (GUID {AgentGuid}).", AgentName, agentGuid);
databaseStorageActor.Tell(new AgentDatabaseStorageActor.StoreAgentDataCommand(configuration, authInfo.Secret, runtimeInfo));
databaseStorageActor.Tell(new AgentDatabaseStorageActor.StoreAgentRuntimeInfoCommand(runtimeInfo));
javaRuntimes = command.JavaRuntimes;
controllerState.UpdateAgentJavaRuntimes(agentGuid, javaRuntimes);
@@ -364,19 +369,15 @@ sealed class AgentActor : ReceiveActor<AgentActor.ICommand>, IWithTimers {
var isCreating = command.IsCreatingInstance;
if (result.Is(ConfigureInstanceResult.Success)) {
string action = isCreating ? "Added" : "Edited";
string relation = isCreating ? "to agent" : "in agent";
Logger.Information(action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) " + relation + " \"{AgentName}\".", instanceName, instanceGuid, AgentName);
string action = isCreating ? "Created" : "Edited";
Logger.Information(action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) in agent \"{AgentName}\".", instanceName, instanceGuid, AgentName);
return CreateOrUpdateInstanceResult.Success;
}
else {
string action = isCreating ? "adding" : "editing";
string relation = isCreating ? "to agent" : "in agent";
string action = isCreating ? "creating" : "editing";
string reason = result.Into(ConfigureInstanceResultExtensions.ToSentence, InstanceActionFailureExtensions.ToSentence);
Logger.Information("Failed " + action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) " + relation + " \"{AgentName}\". {ErrorMessage}", instanceName, instanceGuid, AgentName, reason);
Logger.Information("Failed " + action + " instance \"{InstanceName}\" (GUID {InstanceGuid}) in agent \"{AgentName}\". {ErrorMessage}", instanceName, instanceGuid, AgentName, reason);
return CreateOrUpdateInstanceResult.UnknownError;
}

View File

@@ -5,7 +5,6 @@ using Phantom.Controller.Database.Entities;
using Phantom.Controller.Database.Repositories;
using Phantom.Utils.Actor;
using Phantom.Utils.Logging;
using Phantom.Utils.Rpc;
using Serilog;
namespace Phantom.Controller.Services.Agents;
@@ -25,17 +24,16 @@ sealed class AgentDatabaseStorageActor : ReceiveActor<AgentDatabaseStorageActor.
private readonly IDbContextProvider dbProvider;
private readonly CancellationToken cancellationToken;
private StoreAgentDataCommand? storeCommand;
private bool hasScheduledFlush;
private StoreAgentRuntimeInfoCommand? storeRuntimeInfoCommand;
private AgentDatabaseStorageActor(Init init) {
this.agentGuid = init.AgentGuid;
this.dbProvider = init.DbProvider;
this.cancellationToken = init.CancellationToken;
Receive<StoreAgentDataCommand>(StoreAgentData);
ReceiveAsync<FlushAgentDataCommand>(FlushAgentData);
Receive<StoreAgentRuntimeInfoCommand>(StoreAgentRuntimeInfo);
ReceiveAsync<StoreAgentConfigurationCommand>(StoreAgentConfiguration);
ReceiveAsync<FlushAgentRuntimeInfoCommand>(FlushAgentRuntimeInfo);
}
private ValueTask<AgentEntity?> FindAgentEntity(ILazyDbContext db) {
@@ -44,71 +42,84 @@ sealed class AgentDatabaseStorageActor : ReceiveActor<AgentDatabaseStorageActor.
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;
private void StoreAgentData(StoreAgentDataCommand command) {
storeCommand = command;
public sealed record StoreAgentRuntimeInfoCommand(AgentRuntimeInfo RuntimeInfo) : ICommand;
private sealed record FlushAgentRuntimeInfoCommand : ICommand;
private async Task StoreAgentConfiguration(StoreAgentConfigurationCommand command) {
await FlushAgentRuntimeInfo();
bool wasCreated;
string agentName;
await using (var db = dbProvider.Lazy()) {
var entity = db.Ctx.AgentUpsert.Fetch(agentGuid, out wasCreated);
agentName = 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.", agentName, agentGuid);
}
private void StoreAgentRuntimeInfo(StoreAgentRuntimeInfoCommand command) {
storeRuntimeInfoCommand = command;
ScheduleFlush(TimeSpan.FromSeconds(2));
}
private void ScheduleFlush(TimeSpan delay) {
if (!hasScheduledFlush) {
hasScheduledFlush = true;
Timers.StartSingleTimer("FlushChanges", new FlushAgentDataCommand(), delay, Self);
if (storeRuntimeInfoCommand != null) {
Timers.StartSingleTimer("FlushChanges", new FlushAgentRuntimeInfoCommand(), delay, Self);
}
}
private Task FlushAgentData(FlushAgentDataCommand command) {
return FlushAgentData();
private Task FlushAgentRuntimeInfo(FlushAgentRuntimeInfoCommand command) {
return FlushAgentRuntimeInfo();
}
private async Task FlushAgentData() {
hasScheduledFlush = false;
if (storeCommand == null) {
private async Task FlushAgentRuntimeInfo() {
if (storeRuntimeInfoCommand == null) {
return;
}
try {
await using var ctx = dbProvider.Eager();
var entity = ctx.AgentUpsert.Fetch(agentGuid);
string agentName;
await using (var db = dbProvider.Lazy()) {
var entity = await FindAgentEntity(db);
if (entity == null) {
return;
}
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;
agentName = entity.Name;
await ctx.SaveChangesAsync(cancellationToken);
} catch (Exception e) {
ScheduleFlush(TimeSpan.FromSeconds(10));
Logger.Error(e, "Could not store agent \"{AgentName}\" (GUID {AgentGuid}) in database.", storeCommand.Configuration.AgentName, agentGuid);
return;
try {
entity.ProtocolVersion = storeRuntimeInfoCommand.RuntimeInfo.VersionInfo?.ProtocolVersion;
entity.BuildVersion = storeRuntimeInfoCommand.RuntimeInfo.VersionInfo?.BuildVersion;
entity.MaxInstances = storeRuntimeInfoCommand.RuntimeInfo.MaxInstances;
entity.MaxMemory = storeRuntimeInfoCommand.RuntimeInfo.MaxMemory;
await db.Ctx.SaveChangesAsync(cancellationToken);
} catch (Exception e) {
ScheduleFlush(TimeSpan.FromSeconds(10));
Logger.Error(e, "Could not update agent \"{AgentName}\" (GUID {AgentGuid}) in database.", entity.Name, agentGuid);
return;
}
}
Logger.Information("Stored agent \"{AgentName}\" (GUID {AgentGuid}) in database.", storeCommand.Configuration.AgentName, agentGuid);
Logger.Information("Updated agent \"{AgentName}\" (GUID {AgentGuid}) in database.", agentName, agentGuid);
storeCommand = null;
}
private async Task StoreAgentConfiguration(StoreAgentConfigurationCommand command) {
await FlushAgentData();
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);
storeRuntimeInfoCommand = null;
}
}

View File

@@ -37,17 +37,15 @@ sealed class AgentManager(
await foreach (var entity in ctx.Agents.AsAsyncEnumerable().WithCancellation(cancellationToken)) {
var agentGuid = entity.AgentGuid;
var configuration = new AgentConfiguration(entity.Name);
var runtimeInfo = new AgentRuntimeInfo(entity.ProtocolVersion, entity.BuildVersion, entity.MaxInstances, entity.MaxMemory);
if (AddAgent(agentGuid, configuration, entity.AuthSecret!, runtimeInfo)) {
if (AddAgent(loggedInUserGuid: null, agentGuid, entity.Configuration, entity.AuthSecret!, entity.RuntimeInfo)) {
Logger.Information("Loaded agent \"{AgentName}\" (GUID {AgentGuid}) from database.", entity.Name, agentGuid);
}
}
}
private bool AddAgent(Guid agentGuid, AgentConfiguration configuration, AuthSecret authSecret, AgentRuntimeInfo runtimeInfo) {
var init = new AgentActor.Init(agentGuid, configuration, authSecret, runtimeInfo, agentConnectionKeys, controllerState, minecraftVersions, dbProvider, cancellationToken);
private bool AddAgent(Guid? loggedInUserGuid, Guid agentGuid, AgentConfiguration configuration, AuthSecret authSecret, AgentRuntimeInfo runtimeInfo) {
var init = new AgentActor.Init(loggedInUserGuid, agentGuid, configuration, authSecret, runtimeInfo, agentConnectionKeys, controllerState, minecraftVersions, dbProvider, cancellationToken);
var name = "Agent:" + agentGuid;
return agentsByAgentGuid.TryAdd(agentGuid, actorSystem.ActorOf(AgentActor.Factory(init), name));
}
@@ -89,13 +87,31 @@ sealed class AgentManager(
return true;
}
else {
Logger.Warning("Could not deliver command {CommandType} to non-existent agent {AgentGuid}.", command.GetType().Name, agentGuid);
Logger.Warning("Could not deliver command {CommandType} to unknown agent {AgentGuid}.", command.GetType().Name, agentGuid);
return false;
}
}
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>> {
var loggedInUser = userLoginManager.GetLoggedInUser(authToken);
public Result<CreateOrUpdateAgentResult, UserActionFailure> CreateOrUpdateAgent(LoggedInUser loggedInUser, Guid agentGuid, AgentConfiguration configuration) {
if (!loggedInUser.CheckPermission(Permission.ManageAllAgents)) {
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)) {
return (UserInstanceActionFailure) UserActionFailure.NotAuthorized;
}

View File

@@ -74,7 +74,7 @@ sealed class WebMessageHandlerActor : ReceiveActor<IMessageToController> {
ReceiveAndReplyLater<GetUserRolesMessage, ImmutableDictionary<Guid, ImmutableArray<Guid>>>(GetUserRoles);
ReceiveAndReplyLater<ChangeUserRolesMessage, Result<ChangeUserRolesResult, UserActionFailure>>(ChangeUserRoles);
ReceiveAndReplyLater<DeleteUserMessage, Result<DeleteUserResult, UserActionFailure>>(DeleteUser);
ReceiveAndReplyLater<CreateOrUpdateAgentMessage, Result<CreateOrUpdateAgentResult, UserActionFailure>>(CreateOrUpdateAgentMessage);
ReceiveAndReply<CreateOrUpdateAgentMessage, Result<CreateOrUpdateAgentResult, UserActionFailure>>(CreateOrUpdateAgentMessage);
ReceiveAndReply<GetAgentJavaRuntimesMessage, ImmutableDictionary<Guid, ImmutableArray<TaggedJavaRuntime>>>(GetAgentJavaRuntimes);
ReceiveAndReplyLater<CreateOrUpdateInstanceMessage, Result<CreateOrUpdateInstanceResult, UserInstanceActionFailure>>(CreateOrUpdateInstance);
ReceiveAndReplyLater<LaunchInstanceMessage, Result<LaunchInstanceResult, UserInstanceActionFailure>>(LaunchInstance);
@@ -125,7 +125,7 @@ sealed class WebMessageHandlerActor : ReceiveActor<IMessageToController> {
return userManager.DeleteByGuid(userLoginManager.GetLoggedInUser(message.AuthToken), message.SubjectUserGuid);
}
private Task<Result<CreateOrUpdateAgentResult, UserActionFailure>> CreateOrUpdateAgentMessage(CreateOrUpdateAgentMessage message) {
private Result<CreateOrUpdateAgentResult, UserActionFailure> CreateOrUpdateAgentMessage(CreateOrUpdateAgentMessage message) {
return agentManager.CreateOrUpdateAgent(userLoginManager.GetLoggedInUser(message.AuthToken), message.AgentGuid, message.Configuration);
}

View File

@@ -37,33 +37,33 @@
<small class="font-monospace text-uppercase">@agent.AgentGuid.ToString()</small>
</Cell>
<Cell class="text-end">
@if (runtimeInfo == null) {
<text>N/A</text>
@if (runtimeInfo.MaxInstances is {} maxInstances) {
<ProgressBar Value="@(usedInstances ?? 0)" Maximum="@maxInstances">
@(usedInstances?.ToString() ?? "?") / @maxInstances.ToString()
</ProgressBar>
}
else {
<ProgressBar Value="@(usedInstances ?? 0)" Maximum="@runtimeInfo.MaxInstances">
@(usedInstances?.ToString() ?? "?") / @runtimeInfo.MaxInstances.ToString()
</ProgressBar>
@:N/A
}
</Cell>
<Cell class="text-end">
@if (runtimeInfo == null) {
<text>N/A</text>
@if (runtimeInfo.MaxMemory is {} maxMemory) {
<ProgressBar Value="@(usedMemory ?? 0)" Maximum="@maxMemory.InMegabytes">
@(usedMemory?.ToString() ?? "?") / @maxMemory.InMegabytes.ToString() MB
</ProgressBar>
}
else {
<ProgressBar Value="@(usedMemory ?? 0)" Maximum="@runtimeInfo.MaxMemory.InMegabytes">
@(usedMemory?.ToString() ?? "?") / @runtimeInfo.MaxMemory.InMegabytes.ToString() MB
</ProgressBar>
@:N/A
}
</Cell>
<Cell class="text-condensed">
@if (runtimeInfo == null) {
<text>N/A</text>
@if (runtimeInfo.VersionInfo is {} versionInfo) {
<text>Build: <span class="font-monospace">@versionInfo.BuildVersion</span></text>
<br>
<text>Protocol: <span class="font-monospace">v@(versionInfo.ProtocolVersion.ToString())</span></text>
}
else {
<text>Build: <span class="font-monospace">@runtimeInfo.BuildVersion</span></text>
<br>
<text>Protocol: <span class="font-monospace">v@(runtimeInfo.ProtocolVersion.ToString())</span></text>
@:N/A
}
</Cell>
@switch (agent.ConnectionStatus) {

View File

@@ -33,11 +33,11 @@
return
@<option value="@agent.AgentGuid">
@agent.Configuration.AgentName
@if (runtimeInfo != null) {
@if (runtimeInfo.MaxInstances is not null && runtimeInfo.MaxMemory is not null) {
<text>&bullet;</text>
<text>@(agent.Stats?.RunningInstanceCount.ToString() ?? "?")/@(runtimeInfo.MaxInstances) @(runtimeInfo.MaxInstances == 1 ? "Instance" : "Instances")</text>
<text>&bullet;</text>
<text>@(agent.Stats?.RunningInstanceMemory.InMegabytes.ToString() ?? "?")/@(runtimeInfo.MaxMemory.InMegabytes) MB RAM</text>
<text>@(agent.Stats?.RunningInstanceMemory.InMegabytes.ToString() ?? "?")/@(runtimeInfo.MaxMemory.Value.InMegabytes) MB RAM</text>
}
</option>;
}
@@ -103,8 +103,8 @@
</div>
@{
string? allowedServerPorts = selectedAgent?.RuntimeInfo?.AllowedServerPorts?.ToString();
string? allowedRconPorts = selectedAgent?.RuntimeInfo?.AllowedRconPorts?.ToString();
string? allowedServerPorts = selectedAgent?.RuntimeInfo.AllowedServerPorts?.ToString();
string? allowedRconPorts = selectedAgent?.RuntimeInfo.AllowedRconPorts?.ToString();
}
<div class="col-sm-6 col-xl-2 mb-3">
<FormNumberInput Id="instance-server-port" @bind-Value="form.ServerPort" min="0" max="65535">
@@ -143,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">
<LabelFragment>
@if (maximumMemoryUnits == 0 || selectedAgent?.RuntimeInfo == null) {
@if (maximumMemoryUnits == 0 || selectedAgent?.RuntimeInfo.MaxMemory is not {} maxMemory) {
<text>RAM</text>
}
else {
<text>RAM &bullet; <code>@(form.MemoryAllocation?.InMegabytes ?? 0) / @(selectedAgent.RuntimeInfo.MaxMemory.InMegabytes) MB</code></text>
<text>RAM &bullet; <code>@(form.MemoryAllocation?.InMegabytes ?? 0) / @(maxMemory.InMegabytes) MB</code></text>
}
</LabelFragment>
</FormNumberInput>
@@ -211,7 +211,7 @@
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);
private ushort selectedMemoryUnits = 4;
@@ -252,12 +252,12 @@
public sealed class ServerPortMustBeAllowedAttribute : FormValidationAttribute<ConfigureInstanceFormModel, int> {
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> {
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?> {