Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/Filament/Admin/Resources/Servers/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ public function form(Schema $schema): Schema
->schema($this->transferServer())
->action(function (TransferServerService $transfer, Server $server, $data) {
try {
$transfer->handle($server, Arr::get($data, 'node_id'), Arr::get($data, 'allocation_id'), Arr::get($data, 'allocation_additional', []));
$transfer->handle($server, Arr::get($data, 'node_id'), Arr::get($data, 'allocation_id'), Arr::get($data, 'allocation_additional', []), Arr::get($data, 'backups', []));

Notification::make()
->title(trans('admin/server.notifications.transfer_started'))
Expand Down Expand Up @@ -1053,6 +1053,15 @@ protected function transferServer(): array
->options(fn (Get $get) => Allocation::where('node_id', $get('node_id'))->whereNull('server_id')->when($get('allocation_id'), fn ($query) => $query->whereNot('id', $get('allocation_id')))->get()->mapWithKeys(fn (Allocation $allocation) => [$allocation->id => $allocation->address]))
->searchable(['ip', 'port', 'ip_alias'])
->placeholder(trans('admin/server.select_additional')),
Select::make('backups')
->label(trans('admin/server.backups'))
->multiple()
->searchable()
->helperText(trans('admin/server.warning_backups'))
->prefixIcon('tabler-copy-check')
->disabled(fn (Server $server) => $server->backups->count() === 0)
->options(fn (Server $server) => $server->backups->mapWithKeys(fn ($backup) => [$backup->id => $backup->name ?: $backup->uuid]))
->placeholder(trans('admin/server.select_backups')),
];
}

Expand Down
16 changes: 13 additions & 3 deletions app/Services/Servers/TransferServerService.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backup uuids should be added to the ServerTransfer model.

Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ public function __construct(
private NodeJWTService $nodeJWTService,
) {}

private function notify(ServerTransfer $transfer, UnencryptedToken $token): void
/**
* @param int[] $backup_ids
*/
private function notify(ServerTransfer $transfer, UnencryptedToken $token, array $backup_ids = []): void
{
$backups = [];
if (config('backups.default') === 'wings') {
$backups = $transfer->server->backups->whereIn('id', $backup_ids)->pluck('uuid')->toArray();
}
Http::daemon($transfer->oldNode)->post("/api/servers/{$transfer->server->uuid}/transfer", [
'url' => $transfer->newNode->getConnectionAddress() . '/api/transfers',
'token' => 'Bearer ' . $token->toString(),
'backups' => $backups,
'server' => [
'uuid' => $transfer->server->uuid,
'start_on_completion' => false,
Expand All @@ -39,11 +47,13 @@ private function notify(ServerTransfer $transfer, UnencryptedToken $token): void
* Starts a transfer of a server to a new node.
*
* @param int[] $additional_allocations
* @param int[] $backup_ids
*
* @throws Throwable
*/
public function handle(Server $server, int $node_id, ?int $allocation_id = null, ?array $additional_allocations = []): bool
public function handle(Server $server, int $node_id, ?int $allocation_id = null, ?array $additional_allocations = [], ?array $backup_ids = []): bool
{

$additional_allocations = array_map(intval(...), $additional_allocations);

// Check if the node is viable for the transfer.
Expand Down Expand Up @@ -93,7 +103,7 @@ public function handle(Server $server, int $node_id, ?int $allocation_id = null,
->handle($transfer->newNode, $server->uuid, 'sha256');

// Notify the source node of the pending outgoing transfer.
$this->notify($transfer, $token);
$this->notify($transfer, $token, $backup_ids);

return true;
}
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
'add_allocation' => 'Add Allocation',
'view' => 'View',
'no_log' => 'No Log Available',
'select_backups' => 'Select Backups',
'warning_backups' => 'Be aware, not transferred backups will be deleted.',
'tabs' => [
'information' => 'Information',
'egg_configuration' => 'Egg Configuration',
Expand Down