Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 37 additions & 1 deletion app/Classes/PterodactylClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,42 @@ public function getFreeAllocations(Node $node)
return $freeAllocations;
}

/**
* Check whether a node has reached its allocation limit.
*
* The allocation limit is a per-node setting: it caps the number of
* allocations that may be in use on a single node. When the amount of
* assigned allocations on the node meets or exceeds the limit, no new
* servers can be deployed to that node (but other nodes in the same
* location remain eligible).
*
* @param Node $node
* @return bool
*/
public function nodeHasReachedAllocationLimit(Node $node, int $nodeAllocationLimit = null): bool
Comment thread
MrWeez marked this conversation as resolved.
Outdated
{
// A limit of 0 means "no limit", so the node is never blocked.
$limit = $nodeAllocationLimit ?? $this->allocation_limit;
if ($limit <= 0) {
return false;
}

$response = self::getAllocations($node);
Comment thread
MrWeez marked this conversation as resolved.
Outdated

if (!isset($response['data']) || empty($response['data'])) {
return false;
}

$usedAllocations = 0;
foreach ($response['data'] as $allocation) {
if ($allocation['attributes']['assigned']) {
$usedAllocations++;
}
}

return $usedAllocations >= $limit;
}

Comment thread
MrWeez marked this conversation as resolved.
Outdated
/**
* @param Node $node
* @return array|mixed
Expand All @@ -250,7 +286,7 @@ public function getFreeAllocations(Node $node)
public function getAllocations(Node $node)
{
try {
$response = $this->application->get("application/nodes/{$node->id}/allocations?per_page={$this->allocation_limit}");
$response = $this->application->get("application/nodes/{$node->id}/allocations?per_page={$this->per_page_limit}");
} catch (Exception $e) {
throw self::getException($e->getMessage());
}
Expand Down
12 changes: 11 additions & 1 deletion app/Http/Controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ private function findAvailableNode(string $locationId, Product $product): ?Node
return true;
}

// Check if node has reached its per-node allocation limit.
if ($this->pterodactyl->nodeHasReachedAllocationLimit($node, $node->allocation_limit)) {
return true;
}

// Check if node has free allocations (IP/port)
$freeAllocations = $this->pterodactyl->getFreeAllocations($node);
return empty($freeAllocations);
Expand All @@ -592,7 +597,12 @@ private function findAvailableNodeWithAllocation(string $locationId, Product $pr
->get();

$availableNodes = $nodes->reject(function ($node) use ($product) {
return !$this->pterodactyl->checkNodeResources($node, $product->memory, $product->disk);
if (!$this->pterodactyl->checkNodeResources($node, $product->memory, $product->disk)) {
return true;
}

// Check if node has reached its per-node allocation limit.
return $this->pterodactyl->nodeHasReachedAllocationLimit($node, $node->allocation_limit);
});

foreach ($availableNodes as $node) {
Expand Down
12 changes: 11 additions & 1 deletion app/Services/ServerCreationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ private function findAvailableNode(string $locationId, Product $product): ?Node
return true;
}

// Check if node has reached its per-node allocation limit.
if ($this->pterodactylClient->nodeHasReachedAllocationLimit($node, $node->allocation_limit)) {
return true;
}

// Check if node has free allocations (IP/port)
$freeAllocations = $this->pterodactylClient->getFreeAllocations($node);
return empty($freeAllocations);
Expand All @@ -332,7 +337,12 @@ private function findAvailableNodeWithAllocation(string $locationId, Product $pr
->get();

$availableNodes = $nodes->reject(function ($node) use ($product) {
return !$this->pterodactylClient->checkNodeResources($node, $product->memory, $product->disk);
if (!$this->pterodactylClient->checkNodeResources($node, $product->memory, $product->disk)) {
return true;
}

// Check if node has reached its per-node allocation limit.
return $this->pterodactylClient->nodeHasReachedAllocationLimit($node, $node->allocation_limit);
});

// Try each available node and return the first one with a free allocation.
Expand Down
Loading