mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-23 21:16:52 +01:00
Nullify SwarmUpdateRequest
This commit is contained in:
@@ -776,14 +776,14 @@ namespace Tgstation.Server.Host.Swarm
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the <see cref="SwarmPrepareResult"/>.</returns>
|
||||
async ValueTask<SwarmPrepareResult> PrepareUpdateImpl(ISeekableFileStreamProvider? initiatorProvider, SwarmUpdateRequest updateRequest, CancellationToken cancellationToken)
|
||||
{
|
||||
var version = updateRequest.UpdateVersion!;
|
||||
if (!SwarmMode)
|
||||
{
|
||||
// we still need an active update operation for the TargetVersion
|
||||
updateOperation = new SwarmUpdateOperation(updateRequest.UpdateVersion);
|
||||
updateOperation = new SwarmUpdateOperation(version);
|
||||
return SwarmPrepareResult.SuccessProviderNotRequired;
|
||||
}
|
||||
|
||||
var version = updateRequest.UpdateVersion;
|
||||
var initiator = initiatorProvider != null;
|
||||
logger.LogTrace("PrepareUpdateImpl {version}...", version);
|
||||
|
||||
@@ -868,6 +868,12 @@ namespace Tgstation.Server.Host.Swarm
|
||||
return SwarmPrepareResult.Failure;
|
||||
}
|
||||
|
||||
if (updateRequest.DownloadTickets == null)
|
||||
{
|
||||
logger.LogError("Missing download tickets in update request!");
|
||||
return SwarmPrepareResult.Failure;
|
||||
}
|
||||
|
||||
if (!updateRequest.DownloadTickets.TryGetValue(swarmConfiguration.Identifier!, out var ticket))
|
||||
{
|
||||
logger.Log(
|
||||
@@ -970,7 +976,7 @@ namespace Tgstation.Server.Host.Swarm
|
||||
}
|
||||
|
||||
// The initiator node obviously doesn't create a ticket for itself
|
||||
else if (!weAreInitiator && updateRequest.DownloadTickets.Count != currentUpdateOperation.InvolvedServers.Count - 1)
|
||||
else if (!weAreInitiator && updateRequest.DownloadTickets!.Count != currentUpdateOperation.InvolvedServers.Count - 1)
|
||||
{
|
||||
logger.LogWarning(
|
||||
"Aborting update, {receivedTickets} download tickets were provided but there are {nodesToUpdate} nodes in the swarm that require the package!",
|
||||
@@ -982,7 +988,7 @@ namespace Tgstation.Server.Host.Swarm
|
||||
|
||||
var downloadTicketDictionary = weAreInitiator
|
||||
? await CreateDownloadTickets(initiatorProvider!, currentUpdateOperation.InvolvedServers, cancellationToken)
|
||||
: updateRequest.DownloadTickets;
|
||||
: updateRequest.DownloadTickets!;
|
||||
|
||||
var sourceNode = weAreInitiator
|
||||
? swarmConfiguration.Identifier
|
||||
@@ -998,17 +1004,18 @@ namespace Tgstation.Server.Host.Swarm
|
||||
.Select(node =>
|
||||
{
|
||||
// only send the necessary ticket to each node from the controller
|
||||
Dictionary<string, FileTicketResponse?> localTicketDictionary;
|
||||
Dictionary<string, FileTicketResponse>? localTicketDictionary;
|
||||
var nodeId = node.Identifier!;
|
||||
if (!downloadTicketDictionary.TryGetValue(nodeId, out var ticket)
|
||||
&& nodeId != sourceNode)
|
||||
if (nodeId == sourceNode)
|
||||
localTicketDictionary = null;
|
||||
else if (!downloadTicketDictionary.TryGetValue(nodeId, out var ticket))
|
||||
{
|
||||
logger.LogError("Missing download ticket for node {missingNodeId}!", nodeId);
|
||||
anyFailed = true;
|
||||
return null;
|
||||
}
|
||||
else
|
||||
localTicketDictionary = new Dictionary<string, FileTicketResponse?>
|
||||
localTicketDictionary = new Dictionary<string, FileTicketResponse>
|
||||
{
|
||||
{ nodeId, ticket },
|
||||
};
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.ComponentModel.DataAnnotations;
|
||||
|
||||
using Tgstation.Server.Api.Models.Response;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Tgstation.Server.Host.Swarm
|
||||
{
|
||||
/// <summary>
|
||||
@@ -17,17 +15,17 @@ namespace Tgstation.Server.Host.Swarm
|
||||
/// The TGS <see cref="Version"/> to update to.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public Version UpdateVersion { get; init; }
|
||||
public Version? UpdateVersion { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Api.Models.Internal.SwarmServer.Identifier"/> of the node to download the update package from.
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string SourceNode { get; init; }
|
||||
public string? SourceNode { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The map of <see cref="Api.Models.Internal.SwarmServer.Identifier"/>s to <see cref="FileTicketResponse"/>s for retrieving the update package from the initiating server.
|
||||
/// </summary>
|
||||
public Dictionary<string, FileTicketResponse> DownloadTickets { get; init; }
|
||||
public Dictionary<string, FileTicketResponse>? DownloadTickets { get; init; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user