re-implement backup transfers

This commit is contained in:
Boy132
2026-02-24 14:15:26 +01:00
parent a9f6bcb1e8
commit 1a9cc5f565

View File

@@ -2,7 +2,10 @@
namespace App\Services\Servers;
use App\Extensions\BackupAdapter\BackupAdapterService;
use App\Extensions\BackupAdapter\Schemas\WingsBackupSchema;
use App\Models\Allocation;
use App\Models\Backup;
use App\Models\Node;
use App\Models\Server;
use App\Models\ServerTransfer;
@@ -19,16 +22,28 @@ class TransferServerService
* TransferService constructor.
*/
public function __construct(
private ConnectionInterface $connection,
private NodeJWTService $nodeJWTService,
private readonly ConnectionInterface $connection,
private readonly NodeJWTService $nodeJWTService,
private readonly BackupAdapterService $backupService
) {}
/**
* @param string[] $backup_uuids
*/
/** @param string[] $backup_uuids */ // TODO: add backup uuids to ServerTransfer model
private function notify(ServerTransfer $transfer, UnencryptedToken $token, array $backup_uuids = []): void
{
$backups = []; // TODO
$backups = [];
// Make sure only wings backups are forwarded in the wings request
foreach ($backup_uuids as $uuid) {
$backup = Backup::find($uuid);
if ($backup) {
$schema = $this->backupService->get($backup->backupHost->schema);
if ($schema instanceof WingsBackupSchema) {
$backups[] = $uuid;
}
}
}
Http::daemon($transfer->oldNode)->post("/api/servers/{$transfer->server->uuid}/transfer", [
'url' => $transfer->newNode->getConnectionAddress() . '/api/transfers',
@@ -45,11 +60,11 @@ class TransferServerService
* Starts a transfer of a server to a new node.
*
* @param int[] $additional_allocations
* @param string[] $backup_uuid
* @param string[] $backup_uuids
*
* @throws Throwable
*/
public function handle(Server $server, int $node_id, ?int $allocation_id = null, ?array $additional_allocations = [], ?array $backup_uuid = []): bool
public function handle(Server $server, int $node_id, ?int $allocation_id = null, ?array $additional_allocations = [], ?array $backup_uuids = []): bool
{
$additional_allocations = array_map(intval(...), $additional_allocations);
@@ -100,7 +115,7 @@ class TransferServerService
->handle($transfer->newNode, $server->uuid, 'sha256');
// Notify the source node of the pending outgoing transfer.
$this->notify($transfer, $token, $backup_uuid);
$this->notify($transfer, $token, $backup_uuids);
return true;
}