Remove final refs

This commit is contained in:
Lance Pioch 2024-06-15 06:01:24 -04:00
parent 8ea57bc46b
commit 44e0dd3e09
4 changed files with 19 additions and 10 deletions

View File

@ -10,6 +10,7 @@ use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Query\JoinClause; use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOne;
@ -103,6 +104,16 @@ use App\Exceptions\Http\Server\ServerStateConflictException;
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUuid($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereUuid($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereuuid_short($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereuuid_short($value)
* *
* @property array|null $docker_labels
* @property Collection<Endpoint>|null $ports
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\EggVariable> $eggVariables
* @property-read int|null $egg_variables_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\ServerVariable> $serverVariables
* @property-read int|null $server_variables_count
* @method static \Illuminate\Database\Eloquent\Builder|Server whereDockerLabels($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereInstalledAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server wherePorts($value)
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUuidShort($value)
* @mixin \Eloquent * @mixin \Eloquent
*/ */
class Server extends Model class Server extends Model

View File

@ -2,6 +2,8 @@
namespace App\Services\Allocations; namespace App\Services\Allocations;
use App\Models\Objects\Endpoint;
use Illuminate\Support\Collection;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
use App\Models\Server; use App\Models\Server;
use App\Exceptions\Service\Allocation\AutoAllocationNotEnabledException; use App\Exceptions\Service\Allocation\AutoAllocationNotEnabledException;
@ -45,11 +47,10 @@ class FindAssignableAllocationService
Assert::integerish($start); Assert::integerish($start);
Assert::integerish($end); Assert::integerish($end);
// Get all the currently allocated ports for the node so that we can figure out which port might be available. $ports = $server->node->servers
$ports = $server->node->allocations() ->reduce(fn (Collection $result, $value) => $result->merge($value), collect())
->where('ip', $server->allocation->ip) ->map(fn (Endpoint $endpoint) => $endpoint->port)
->whereBetween('port', [$start, $end]) ->filter(fn (int $port): bool => $port >= $start && $port <= $end);
->pluck('port');
// Compute the difference of the range and the currently created ports, finding // Compute the difference of the range and the currently created ports, finding
// any port that does not already exist in the database. We will then use this // any port that does not already exist in the database. We will then use this
@ -57,7 +58,6 @@ class FindAssignableAllocationService
$available = array_diff(range($start, $end), $ports->toArray()); $available = array_diff(range($start, $end), $ports->toArray());
// Pick a random port out of the remaining available ports. // Pick a random port out of the remaining available ports.
/** @var int $port */
return $available[array_rand($available)]; return $available[array_rand($available)];
} }
} }

View File

@ -66,8 +66,8 @@ class ServerConfigurationStructureService
'allocations' => [ 'allocations' => [
'force_outgoing_ip' => $server->egg->force_outgoing_ip, 'force_outgoing_ip' => $server->egg->force_outgoing_ip,
'default' => [ 'default' => [
'ip' => $server->allocation->ip, 'ip' => $server->getPrimaryEndpoint()->ip,
'port' => $server->allocation->port, 'port' => $server->getPrimaryEndpoint()->port,
], ],
'mappings' => $server->getPortMappings(), 'mappings' => $server->getPortMappings(),
], ],

View File

@ -77,8 +77,6 @@ class ServerDeletionService
} }
} }
$server->allocations()->update(['server_id' => null]);
$server->delete(); $server->delete();
}); });
} }