mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-29 16:44:44 +02:00
simplify AllocationSelectionService
This commit is contained in:
parent
98419bc625
commit
f2a59002bc
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@ -69,7 +69,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Unit tests
|
- name: Unit tests
|
||||||
run: vendor/bin/phpunit tests/Unit
|
run: vendor/bin/phpunit tests/Unit
|
||||||
if: ${{ always() }}
|
|
||||||
env:
|
env:
|
||||||
DB_HOST: UNIT_NO_DB
|
DB_HOST: UNIT_NO_DB
|
||||||
SKIP_MIGRATIONS: true
|
SKIP_MIGRATIONS: true
|
||||||
@ -134,7 +133,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Unit tests
|
- name: Unit tests
|
||||||
run: vendor/bin/phpunit tests/Unit
|
run: vendor/bin/phpunit tests/Unit
|
||||||
if: ${{ always() }}
|
|
||||||
env:
|
env:
|
||||||
DB_HOST: UNIT_NO_DB
|
DB_HOST: UNIT_NO_DB
|
||||||
SKIP_MIGRATIONS: true
|
SKIP_MIGRATIONS: true
|
||||||
|
@ -6,7 +6,6 @@ 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
|
||||||
{
|
{
|
||||||
@ -122,17 +121,7 @@ class AllocationSelectionService
|
|||||||
$discard = $this->getDiscardableDedicatedAllocations($nodes);
|
$discard = $this->getDiscardableDedicatedAllocations($nodes);
|
||||||
|
|
||||||
if (!empty($discard)) {
|
if (!empty($discard)) {
|
||||||
if (DB::getDriverName() === 'sqlite') {
|
$query->whereNotIn('ip', $discard);
|
||||||
$query->whereNotIn(
|
|
||||||
Allocation::query()->raw('node_id || "-" || ip'),
|
|
||||||
$discard
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$query->whereNotIn(
|
|
||||||
Allocation::query()->raw('CONCAT_WS("-", node_id, ip)'),
|
|
||||||
$discard
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +129,7 @@ class AllocationSelectionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a concatenated result set of node ips that already have at least one
|
* Return a result set of node ips that already have at least one
|
||||||
* server assigned to that IP. This allows for filtering out sets for
|
* server assigned to that IP. This allows for filtering out sets for
|
||||||
* dedicated allocation IPs.
|
* dedicated allocation IPs.
|
||||||
*
|
*
|
||||||
@ -149,30 +138,15 @@ class AllocationSelectionService
|
|||||||
*/
|
*/
|
||||||
private function getDiscardableDedicatedAllocations(array $nodes = []): array
|
private function getDiscardableDedicatedAllocations(array $nodes = []): array
|
||||||
{
|
{
|
||||||
if (DB::getDriverName() === 'sqlite') {
|
$query = Allocation::query()->whereNotNull('server_id');
|
||||||
$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');
|
|
||||||
|
|
||||||
if (!empty($nodes)) {
|
if (!empty($nodes)) {
|
||||||
$query->whereIn('node_id', $nodes);
|
$query->whereIn('node_id', $nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query->whereNotNull('server_id')
|
return $query->groupBy('ip')
|
||||||
->groupByRaw('CONCAT(node_id, ip)')
|
|
||||||
->get()
|
->get()
|
||||||
->pluck('result')
|
->pluck('ip')
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user