mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 08:44:46 +02:00
update AllocationSelectionService
This commit is contained in:
parent
9761c3762d
commit
e82a3b838c
@ -6,6 +6,7 @@ use App\Models\Allocation;
|
|||||||
use App\Exceptions\DisplayException;
|
use App\Exceptions\DisplayException;
|
||||||
use App\Services\Allocations\AssignmentService;
|
use App\Services\Allocations\AssignmentService;
|
||||||
use App\Exceptions\Service\Deployment\NoViableAllocationException;
|
use App\Exceptions\Service\Deployment\NoViableAllocationException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class AllocationSelectionService
|
class AllocationSelectionService
|
||||||
{
|
{
|
||||||
@ -121,12 +122,19 @@ class AllocationSelectionService
|
|||||||
$discard = $this->getDiscardableDedicatedAllocations($nodes);
|
$discard = $this->getDiscardableDedicatedAllocations($nodes);
|
||||||
|
|
||||||
if (!empty($discard)) {
|
if (!empty($discard)) {
|
||||||
|
if (DB::getDriverName() === 'sqlite') {
|
||||||
|
$query->whereNotIn(
|
||||||
|
Allocation::query()->raw('node_id || "-" || ip'),
|
||||||
|
$discard
|
||||||
|
);
|
||||||
|
} else {
|
||||||
$query->whereNotIn(
|
$query->whereNotIn(
|
||||||
Allocation::query()->raw('CONCAT_WS("-", node_id, ip)'),
|
Allocation::query()->raw('CONCAT_WS("-", node_id, ip)'),
|
||||||
$discard
|
$discard
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $query->inRandomOrder()->first();
|
return $query->inRandomOrder()->first();
|
||||||
}
|
}
|
||||||
@ -141,6 +149,20 @@ class AllocationSelectionService
|
|||||||
*/
|
*/
|
||||||
private function getDiscardableDedicatedAllocations(array $nodes = []): array
|
private function getDiscardableDedicatedAllocations(array $nodes = []): array
|
||||||
{
|
{
|
||||||
|
if (DB::getDriverName() === 'sqlite') {
|
||||||
|
$query = Allocation::query()->selectRaw('(node_id || "-" || ip) as result');
|
||||||
|
|
||||||
|
if (!empty($nodes)) {
|
||||||
|
$query->whereIn('node_id', $nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query->whereNotNull('server_id')
|
||||||
|
->groupByRaw('node_id || ip')
|
||||||
|
->get()
|
||||||
|
->pluck('result')
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
$query = Allocation::query()->selectRaw('CONCAT_WS("-", node_id, ip) as result');
|
$query = Allocation::query()->selectRaw('CONCAT_WS("-", node_id, ip) as result');
|
||||||
|
|
||||||
if (!empty($nodes)) {
|
if (!empty($nodes)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user