diff --git a/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php b/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php deleted file mode 100644 index 3201c7b7d..000000000 --- a/app/Http/Controllers/Api/Application/Servers/ServerDetailsController.php +++ /dev/null @@ -1,55 +0,0 @@ -detailsModificationService->returnUpdatedModel()->handle( - $server, - $request->validated() - ); - - return $this->fractal->item($server) - ->transformWith(ServerTransformer::class) - ->toArray(); - } - - /** - * Update the build details for a specific server. - * - * @throws \Throwable - */ - public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array - { - $server = $this->buildModificationService->handle($server, $request->validated()); - - return $this->fractal->item($server) - ->transformWith(ServerTransformer::class) - ->toArray(); - } -} diff --git a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php index 6a8956729..4f8bd872c 100644 --- a/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php +++ b/app/Http/Requests/Api/Application/Servers/StoreServerRequest.php @@ -67,7 +67,7 @@ class StoreServerRequest extends ApplicationApiRequest 'io' => array_get($data, 'limits.io'), 'threads' => array_get($data, 'limits.threads'), 'cpu' => array_get($data, 'limits.cpu'), - 'oom_disabled' => !array_get($data, 'limits.oom_killer'), + 'oom_killer' => array_get($data, 'limits.oom_killer'), 'allocation_limit' => array_get($data, 'feature_limits.allocations'), 'backup_limit' => array_get($data, 'feature_limits.backups'), diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php deleted file mode 100644 index 03bbd08ec..000000000 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php +++ /dev/null @@ -1,127 +0,0 @@ -route()->parameter('server')); - - return [ - 'allocation' => $rules['allocation_id'], - 'oom_disabled' => $rules['oom_disabled'], - - 'limits' => 'sometimes|array', - 'limits.memory' => $this->requiredToOptional('memory', $rules['memory'], true), - 'limits.swap' => $this->requiredToOptional('swap', $rules['swap'], true), - 'limits.io' => $this->requiredToOptional('io', $rules['io'], true), - 'limits.cpu' => $this->requiredToOptional('cpu', $rules['cpu'], true), - 'limits.threads' => $this->requiredToOptional('threads', $rules['threads'], true), - 'limits.disk' => $this->requiredToOptional('disk', $rules['disk'], true), - - // Legacy rules to maintain backwards compatible API support without requiring - // a major version bump. - // - // @see https://github.com/pterodactyl/panel/issues/1500 - 'memory' => $this->requiredToOptional('memory', $rules['memory']), - 'swap' => $this->requiredToOptional('swap', $rules['swap']), - 'io' => $this->requiredToOptional('io', $rules['io']), - 'cpu' => $this->requiredToOptional('cpu', $rules['cpu']), - 'threads' => $this->requiredToOptional('threads', $rules['threads']), - 'disk' => $this->requiredToOptional('disk', $rules['disk']), - - 'add_allocations' => 'bail|array', - 'add_allocations.*' => 'integer', - 'remove_allocations' => 'bail|array', - 'remove_allocations.*' => 'integer', - - 'feature_limits' => 'required|array', - 'feature_limits.databases' => $rules['database_limit'], - 'feature_limits.allocations' => $rules['allocation_limit'], - 'feature_limits.backups' => $rules['backup_limit'], - ]; - } - - /** - * Convert the allocation field into the expected format for the service handler. - * - * @param string|null $key - * @param string|array|null $default - * - * @return mixed - */ - public function validated($key = null, $default = null) - { - $data = parent::validated(); - - $data['allocation_id'] = $data['allocation']; - $data['database_limit'] = $data['feature_limits']['databases'] ?? null; - $data['allocation_limit'] = $data['feature_limits']['allocations'] ?? null; - $data['backup_limit'] = $data['feature_limits']['backups'] ?? null; - unset($data['allocation'], $data['feature_limits']); - - // Adjust the limits field to match what is expected by the model. - if (!empty($data['limits'])) { - foreach ($data['limits'] as $key => $value) { - $data[$key] = $value; - } - - unset($data['limits']); - } - - if (!is_null($key)) { - return Arr::get($data, $key, $default); - } - - return $data; - } - - /** - * Custom attributes to use in error message responses. - * - * @return array - */ - public function attributes() - { - return [ - 'add_allocations' => 'allocations to add', - 'remove_allocations' => 'allocations to remove', - 'add_allocations.*' => 'allocation to add', - 'remove_allocations.*' => 'allocation to remove', - 'feature_limits.databases' => 'Database Limit', - 'feature_limits.allocations' => 'Allocation Limit', - 'feature_limits.backups' => 'Backup Limit', - ]; - } - - /** - * Converts existing rules for certain limits into a format that maintains backwards - * compatability with the old API endpoint while also supporting a more correct API - * call. - * - * @return array - * - * @see https://github.com/pterodactyl/panel/issues/1500 - */ - protected function requiredToOptional(string $field, array $rules, bool $limits = false) - { - if (!in_array('required', $rules)) { - return $rules; - } - - return (new Collection($rules)) - ->filter(function ($value) { - return $value !== 'required'; - }) - ->prepend($limits ? 'required_with:limits' : 'required_without:limits') - ->toArray(); - } -} diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php deleted file mode 100644 index ce181bae3..000000000 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerDetailsRequest.php +++ /dev/null @@ -1,55 +0,0 @@ -route()->parameter('server')); - - return [ - 'external_id' => $rules['external_id'], - 'name' => $rules['name'], - 'user' => $rules['owner_id'], - 'description' => array_merge(['nullable'], $rules['description']), - ]; - } - - /** - * Convert the posted data into the correct format that is expected - * by the application. - * - * @param string|null $key - * @param string|array|null $default - */ - public function validated($key = null, $default = null) - { - $data = [ - 'external_id' => $this->input('external_id'), - 'name' => $this->input('name'), - 'owner_id' => $this->input('user'), - 'description' => $this->input('description'), - ]; - - return is_null($key) ? $data : Arr::get($data, $key, $default); - } - - /** - * Rename some of the attributes in error messages to clarify the field - * being discussed. - */ - public function attributes(): array - { - return [ - 'user' => 'User ID', - 'name' => 'Server Name', - ]; - } -} diff --git a/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php b/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php index a588c381c..faa8ddb1c 100644 --- a/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php +++ b/app/Http/Requests/Api/Application/Servers/UpdateServerRequest.php @@ -61,7 +61,7 @@ class UpdateServerRequest extends ApplicationApiRequest 'io' => array_get($data, 'limits.io'), 'threads' => array_get($data, 'limits.threads'), 'cpu' => array_get($data, 'limits.cpu'), - 'oom_disabled' => !array_get($data, 'limits.oom_killer'), + 'oom_killer' => array_get($data, 'limits.oom_killer'), 'allocation_limit' => array_get($data, 'feature_limits.allocations'), 'backup_limit' => array_get($data, 'feature_limits.backups'), diff --git a/app/Models/Server.php b/app/Models/Server.php index e8560512a..6502a3410 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -31,7 +31,7 @@ use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException; * @property int $io * @property int $cpu * @property string|null $threads - * @property bool $oom_disabled + * @property bool $oom_killer * @property int $allocation_id * @property int $nest_id * @property int $egg_id @@ -90,7 +90,7 @@ use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException; * @method static \Illuminate\Database\Eloquent\Builder|Server whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereNestId($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereNodeId($value) - * @method static \Illuminate\Database\Eloquent\Builder|Server whereOomDisabled($value) + * @method static \Illuminate\Database\Eloquent\Builder|Server whereOomKiller($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereOwnerId($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereSkipScripts($value) * @method static \Illuminate\Database\Eloquent\Builder|Server whereStartup($value) @@ -131,7 +131,7 @@ class Server extends Model */ protected $attributes = [ 'status' => self::STATUS_INSTALLING, - 'oom_disabled' => true, + 'oom_killer' => false, 'installed_at' => null, ]; @@ -162,7 +162,7 @@ class Server extends Model 'io' => 'required|numeric|between:10,1000', 'cpu' => 'required|numeric|min:0', 'threads' => 'nullable|regex:/^[0-9-,]+$/', - 'oom_disabled' => 'sometimes|boolean', + 'oom_killer' => 'sometimes|boolean', 'disk' => 'required|numeric|min:0', 'allocation_id' => 'required|bail|unique:servers|exists:allocations,id', 'nest_id' => 'required|exists:nests,id', @@ -187,7 +187,7 @@ class Server extends Model 'disk' => 'integer', 'io' => 'integer', 'cpu' => 'integer', - 'oom_disabled' => 'boolean', + 'oom_killer' => 'boolean', 'allocation_id' => 'integer', 'nest_id' => 'integer', 'egg_id' => 'integer', diff --git a/app/Services/Servers/BuildModificationService.php b/app/Services/Servers/BuildModificationService.php index b068933b3..88e48177e 100644 --- a/app/Services/Servers/BuildModificationService.php +++ b/app/Services/Servers/BuildModificationService.php @@ -46,7 +46,7 @@ class BuildModificationService // If any of these values are passed through in the data array go ahead and set // them correctly on the server model. - $merge = Arr::only($data, ['oom_disabled', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']); + $merge = Arr::only($data, ['oom_killer', 'memory', 'swap', 'io', 'cpu', 'threads', 'disk', 'allocation_id']); $server->forceFill(array_merge($merge, [ 'allocation_limit' => Arr::get($data, 'allocation_limit', 0) ?? null, diff --git a/app/Services/Servers/ServerConfigurationStructureService.php b/app/Services/Servers/ServerConfigurationStructureService.php index af6ba906f..1ffbe7792 100644 --- a/app/Services/Servers/ServerConfigurationStructureService.php +++ b/app/Services/Servers/ServerConfigurationStructureService.php @@ -59,7 +59,9 @@ class ServerConfigurationStructureService 'cpu_limit' => $server->cpu, 'threads' => $server->threads, 'disk_space' => $server->disk, - 'oom_disabled' => $server->oom_disabled, + // TODO: remove oom_disabled and use oom_killer, this requires a Wings update. + 'oom_disabled' => !$server->oom_killer, + 'oom_killer' => $server->oom_killer, ], 'container' => [ 'image' => $server->image, @@ -105,7 +107,7 @@ class ServerConfigurationStructureService return $item->pluck('port'); })->toArray(), 'env' => $this->environment->handle($server), - 'oom_disabled' => $server->oom_disabled, + 'oom_disabled' => !$server->oom_killer, 'memory' => (int) $server->memory, 'swap' => (int) $server->swap, 'io' => (int) $server->io, diff --git a/app/Services/Servers/ServerCreationService.php b/app/Services/Servers/ServerCreationService.php index 62e848aa0..9530bd9da 100644 --- a/app/Services/Servers/ServerCreationService.php +++ b/app/Services/Servers/ServerCreationService.php @@ -153,7 +153,7 @@ class ServerCreationService 'io' => Arr::get($data, 'io'), 'cpu' => Arr::get($data, 'cpu'), 'threads' => Arr::get($data, 'threads'), - 'oom_disabled' => Arr::get($data, 'oom_disabled') ?? true, + 'oom_killer' => Arr::get($data, 'oom_killer') ?? false, 'allocation_id' => Arr::get($data, 'allocation_id'), 'nest_id' => Arr::get($data, 'nest_id'), 'egg_id' => Arr::get($data, 'egg_id'), diff --git a/app/Transformers/Api/Application/ServerTransformer.php b/app/Transformers/Api/Application/ServerTransformer.php index f76f192d9..f34b1232f 100644 --- a/app/Transformers/Api/Application/ServerTransformer.php +++ b/app/Transformers/Api/Application/ServerTransformer.php @@ -64,7 +64,7 @@ class ServerTransformer extends Transformer 'disk' => $model->disk, 'io' => $model->io, 'memory' => $model->memory, - 'oom_killer' => !$model->oom_disabled, + 'oom_killer' => $model->oom_killer, 'swap' => $model->swap, 'threads' => $model->threads, ], diff --git a/app/Transformers/Api/Client/ServerTransformer.php b/app/Transformers/Api/Client/ServerTransformer.php index 01a2d135b..56ad04860 100644 --- a/app/Transformers/Api/Client/ServerTransformer.php +++ b/app/Transformers/Api/Client/ServerTransformer.php @@ -55,7 +55,7 @@ class ServerTransformer extends Transformer 'io' => $server->io, 'cpu' => $server->cpu, 'threads' => $server->threads, - 'oom_disabled' => $server->oom_disabled, + 'oom_killer' => $server->oom_killer, ], 'invocation' => $service->handle($server, !$user->can(Permission::ACTION_STARTUP_READ, $server)), 'docker_image' => $server->image, diff --git a/database/Factories/ServerFactory.php b/database/Factories/ServerFactory.php index d89bd6a56..0e2cb07f8 100644 --- a/database/Factories/ServerFactory.php +++ b/database/Factories/ServerFactory.php @@ -37,7 +37,7 @@ class ServerFactory extends Factory 'io' => 500, 'cpu' => 0, 'threads' => null, - 'oom_disabled' => 0, + 'oom_killer' => true, 'startup' => '/bin/bash echo "hello world"', 'image' => 'foo/bar:latest', 'allocation_limit' => null, diff --git a/database/migrations/2023_01_17_185605_rename_oom_disabled_column_to_oom_killer.php b/database/migrations/2023_01_17_185605_rename_oom_disabled_column_to_oom_killer.php new file mode 100644 index 000000000..fb6dfe8e0 --- /dev/null +++ b/database/migrations/2023_01_17_185605_rename_oom_disabled_column_to_oom_killer.php @@ -0,0 +1,44 @@ +tinyInteger('oom_killer')->unsigned()->default(1)->after('oom_disabled'); + }); + + DB::table('servers')->select(['id', 'oom_disabled'])->cursor()->each(function ($server) { + DB::table('servers')->where('id', $server->id)->update(['oom_killer' => !$server->oom_disabled]); + }); + + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('oom_disabled'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('servers', function (Blueprint $table) { + $table->tinyInteger('oom_disabled')->unsigned()->default(0)->after('oom_killer'); + }); + + DB::table('servers')->select(['id', 'oom_killer'])->cursor()->each(function ($server) { + DB::table('servers')->where('id', $server->id)->update(['oom_disabled' => !$server->oom_killer]); + }); + + Schema::table('servers', function (Blueprint $table) { + $table->dropColumn('oom_killer'); + }); + } +}; diff --git a/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx b/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx index 144102c5e..523004a4d 100644 --- a/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx +++ b/resources/scripts/components/admin/servers/ServerSettingsContainer.tsx @@ -52,8 +52,6 @@ export default () => { io: server.limits.io, cpu: server.limits.cpu, threads: server.limits.threads || '', - // This value is inverted to have the switch be on when the - // OOM Killer is enabled, rather than when disabled. oomKiller: server.limits.oomKiller, }, featureLimits: { diff --git a/tests/Integration/Services/Servers/BuildModificationServiceTest.php b/tests/Integration/Services/Servers/BuildModificationServiceTest.php index f63efee9e..720070989 100644 --- a/tests/Integration/Services/Servers/BuildModificationServiceTest.php +++ b/tests/Integration/Services/Servers/BuildModificationServiceTest.php @@ -114,7 +114,7 @@ class BuildModificationServiceTest extends IntegrationTestCase $this->daemonServerRepository->expects('sync')->withNoArgs()->andReturnUndefined(); $response = $this->getService()->handle($server, [ - 'oom_disabled' => false, + 'oom_killer' => true, 'memory' => 256, 'swap' => 128, 'io' => 600, @@ -126,7 +126,7 @@ class BuildModificationServiceTest extends IntegrationTestCase 'allocation_limit' => 20, ]); - $this->assertFalse($response->oom_disabled); + $this->assertTrue($response->oom_killer); $this->assertSame(256, $response->memory); $this->assertSame(128, $response->swap); $this->assertSame(600, $response->io); diff --git a/tests/Integration/Services/Servers/ServerCreationServiceTest.php b/tests/Integration/Services/Servers/ServerCreationServiceTest.php index 3b9da4d91..0cb60de1a 100644 --- a/tests/Integration/Services/Servers/ServerCreationServiceTest.php +++ b/tests/Integration/Services/Servers/ServerCreationServiceTest.php @@ -145,7 +145,7 @@ class ServerCreationServiceTest extends IntegrationTestCase $this->assertSame($allocations[4]->id, $response->allocations[1]->id); $this->assertFalse($response->isSuspended()); - $this->assertTrue($response->oom_disabled); + $this->assertFalse($response->oom_killer); $this->assertSame(0, $response->database_limit); $this->assertSame(0, $response->allocation_limit); $this->assertSame(0, $response->backup_limit);