Remove unnecessary API calls to daemon
This commit is contained in:
parent
59bfc212c9
commit
34ffcdae7a
10 changed files with 10 additions and 312 deletions
|
@ -1,109 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Pterodactyl - Panel
|
|
||||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
|
||||||
*
|
|
||||||
* This software is licensed under the terms of the MIT license.
|
|
||||||
* https://opensource.org/licenses/MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Pterodactyl\Console\Commands\Server;
|
|
||||||
|
|
||||||
use Webmozart\Assert\Assert;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use GuzzleHttp\Exception\RequestException;
|
|
||||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
|
||||||
use Pterodactyl\Services\Servers\ServerConfigurationStructureService;
|
|
||||||
|
|
||||||
class RebuildServerCommand extends Command
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
|
||||||
*/
|
|
||||||
protected $configurationStructureService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
|
||||||
*/
|
|
||||||
protected $daemonRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $description = 'Rebuild a single server, all servers on a node, or all servers on the panel.';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Contracts\Repository\ServerRepositoryInterface
|
|
||||||
*/
|
|
||||||
protected $repository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $signature = 'p:server:rebuild
|
|
||||||
{server? : The ID of the server to rebuild.}
|
|
||||||
{--node= : ID of the node to rebuild all servers on. Ignored if server is passed.}';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RebuildServerCommand constructor.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonRepository
|
|
||||||
* @param \Pterodactyl\Services\Servers\ServerConfigurationStructureService $configurationStructureService
|
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
|
||||||
*/
|
|
||||||
public function __construct(
|
|
||||||
DaemonServerRepository $daemonRepository,
|
|
||||||
ServerConfigurationStructureService $configurationStructureService,
|
|
||||||
ServerRepositoryInterface $repository
|
|
||||||
) {
|
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->configurationStructureService = $configurationStructureService;
|
|
||||||
$this->daemonRepository = $daemonRepository;
|
|
||||||
$this->repository = $repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle command execution.
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$servers = $this->getServersToProcess();
|
|
||||||
$bar = $this->output->createProgressBar(count($servers));
|
|
||||||
|
|
||||||
$servers->each(function ($server) use ($bar) {
|
|
||||||
$bar->clear();
|
|
||||||
$json = array_merge($this->configurationStructureService->handle($server), ['rebuild' => true]);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->daemonRepository->setServer($server)->update($json);
|
|
||||||
} catch (RequestException $exception) {
|
|
||||||
$this->output->error(trans('command/messages.server.rebuild_failed', [
|
|
||||||
'name' => $server->name,
|
|
||||||
'id' => $server->id,
|
|
||||||
'node' => $server->node->name,
|
|
||||||
'message' => $exception->getMessage(),
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
$bar->advance();
|
|
||||||
$bar->display();
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->line('');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the servers to be rebuilt.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Collection
|
|
||||||
*/
|
|
||||||
private function getServersToProcess()
|
|
||||||
{
|
|
||||||
Assert::nullOrIntegerish($this->argument('server'), 'Value passed in server argument must be null or an integer, received %s.');
|
|
||||||
Assert::nullOrIntegerish($this->option('node'), 'Value passed in node option must be null or integer, received %s.');
|
|
||||||
|
|
||||||
return $this->repository->getDataForRebuild($this->argument('server'), $this->option('node'));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,7 +18,6 @@ use Pterodactyl\Http\Controllers\Controller;
|
||||||
use Pterodactyl\Services\Servers\SuspensionService;
|
use Pterodactyl\Services\Servers\SuspensionService;
|
||||||
use Pterodactyl\Services\Servers\ServerDeletionService;
|
use Pterodactyl\Services\Servers\ServerDeletionService;
|
||||||
use Pterodactyl\Services\Servers\ReinstallServerService;
|
use Pterodactyl\Services\Servers\ReinstallServerService;
|
||||||
use Pterodactyl\Services\Servers\ContainerRebuildService;
|
|
||||||
use Pterodactyl\Services\Servers\BuildModificationService;
|
use Pterodactyl\Services\Servers\BuildModificationService;
|
||||||
use Pterodactyl\Services\Databases\DatabasePasswordService;
|
use Pterodactyl\Services\Databases\DatabasePasswordService;
|
||||||
use Pterodactyl\Services\Servers\DetailsModificationService;
|
use Pterodactyl\Services\Servers\DetailsModificationService;
|
||||||
|
@ -54,11 +53,6 @@ class ServersController extends Controller
|
||||||
*/
|
*/
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Services\Servers\ContainerRebuildService
|
|
||||||
*/
|
|
||||||
protected $containerRebuildService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
|
* @var \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface
|
||||||
*/
|
*/
|
||||||
|
@ -121,7 +115,6 @@ class ServersController extends Controller
|
||||||
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
|
* @param \Pterodactyl\Contracts\Repository\AllocationRepositoryInterface $allocationRepository
|
||||||
* @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService
|
* @param \Pterodactyl\Services\Servers\BuildModificationService $buildModificationService
|
||||||
* @param \Illuminate\Contracts\Config\Repository $config
|
* @param \Illuminate\Contracts\Config\Repository $config
|
||||||
* @param \Pterodactyl\Services\Servers\ContainerRebuildService $containerRebuildService
|
|
||||||
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService
|
* @param \Pterodactyl\Services\Databases\DatabaseManagementService $databaseManagementService
|
||||||
* @param \Pterodactyl\Services\Databases\DatabasePasswordService $databasePasswordService
|
* @param \Pterodactyl\Services\Databases\DatabasePasswordService $databasePasswordService
|
||||||
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
|
* @param \Pterodactyl\Contracts\Repository\DatabaseRepositoryInterface $databaseRepository
|
||||||
|
@ -139,7 +132,6 @@ class ServersController extends Controller
|
||||||
AllocationRepositoryInterface $allocationRepository,
|
AllocationRepositoryInterface $allocationRepository,
|
||||||
BuildModificationService $buildModificationService,
|
BuildModificationService $buildModificationService,
|
||||||
ConfigRepository $config,
|
ConfigRepository $config,
|
||||||
ContainerRebuildService $containerRebuildService,
|
|
||||||
DatabaseManagementService $databaseManagementService,
|
DatabaseManagementService $databaseManagementService,
|
||||||
DatabasePasswordService $databasePasswordService,
|
DatabasePasswordService $databasePasswordService,
|
||||||
DatabaseRepositoryInterface $databaseRepository,
|
DatabaseRepositoryInterface $databaseRepository,
|
||||||
|
@ -156,7 +148,6 @@ class ServersController extends Controller
|
||||||
$this->allocationRepository = $allocationRepository;
|
$this->allocationRepository = $allocationRepository;
|
||||||
$this->buildModificationService = $buildModificationService;
|
$this->buildModificationService = $buildModificationService;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->containerRebuildService = $containerRebuildService;
|
|
||||||
$this->databaseHostRepository = $databaseHostRepository;
|
$this->databaseHostRepository = $databaseHostRepository;
|
||||||
$this->databaseManagementService = $databaseManagementService;
|
$this->databaseManagementService = $databaseManagementService;
|
||||||
$this->databasePasswordService = $databasePasswordService;
|
$this->databasePasswordService = $databasePasswordService;
|
||||||
|
@ -235,21 +226,6 @@ class ServersController extends Controller
|
||||||
return redirect()->route('admin.servers.view.manage', $server->id);
|
return redirect()->route('admin.servers.view.manage', $server->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup a server to have a container rebuild.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Models\Server $server
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
*/
|
|
||||||
public function rebuildContainer(Server $server)
|
|
||||||
{
|
|
||||||
$this->containerRebuildService->handle($server);
|
|
||||||
$this->alert->success(trans('admin/server.alerts.rebuild_on_boot'))->flash();
|
|
||||||
|
|
||||||
return redirect()->route('admin.servers.view.manage', $server->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage the suspension status for a server.
|
* Manage the suspension status for a server.
|
||||||
*
|
*
|
||||||
|
@ -302,7 +278,7 @@ class ServersController extends Controller
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
* @throws \Throwable
|
||||||
*/
|
*/
|
||||||
public function delete(Request $request, Server $server)
|
public function delete(Request $request, Server $server)
|
||||||
{
|
{
|
||||||
|
@ -320,7 +296,6 @@ class ServersController extends Controller
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
*
|
*
|
||||||
* @throws \Illuminate\Validation\ValidationException
|
* @throws \Illuminate\Validation\ValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -63,15 +63,16 @@ class ServerDetailsController extends ApplicationApiController
|
||||||
* Update the build details for a specific server.
|
* Update the build details for a specific server.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request
|
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\UpdateServerBuildConfigurationRequest $request
|
||||||
|
* @param \Pterodactyl\Models\Server $server
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
*/
|
*/
|
||||||
public function build(UpdateServerBuildConfigurationRequest $request): array
|
public function build(UpdateServerBuildConfigurationRequest $request, Server $server): array
|
||||||
{
|
{
|
||||||
$server = $this->buildModificationService->handle($request->getModel(Server::class), $request->validated());
|
$server = $this->buildModificationService->handle($server, $request->validated());
|
||||||
|
|
||||||
return $this->fractal->item($server)
|
return $this->fractal->item($server)
|
||||||
->transformWith($this->getTransformer(ServerTransformer::class))
|
->transformWith($this->getTransformer(ServerTransformer::class))
|
||||||
|
|
|
@ -6,17 +6,11 @@ use Illuminate\Http\Response;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use Pterodactyl\Services\Servers\SuspensionService;
|
use Pterodactyl\Services\Servers\SuspensionService;
|
||||||
use Pterodactyl\Services\Servers\ReinstallServerService;
|
use Pterodactyl\Services\Servers\ReinstallServerService;
|
||||||
use Pterodactyl\Services\Servers\ContainerRebuildService;
|
|
||||||
use Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest;
|
use Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest;
|
||||||
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
use Pterodactyl\Http\Controllers\Api\Application\ApplicationApiController;
|
||||||
|
|
||||||
class ServerManagementController extends ApplicationApiController
|
class ServerManagementController extends ApplicationApiController
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Services\Servers\ContainerRebuildService
|
|
||||||
*/
|
|
||||||
private $rebuildService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Servers\ReinstallServerService
|
* @var \Pterodactyl\Services\Servers\ReinstallServerService
|
||||||
*/
|
*/
|
||||||
|
@ -30,18 +24,15 @@ class ServerManagementController extends ApplicationApiController
|
||||||
/**
|
/**
|
||||||
* SuspensionController constructor.
|
* SuspensionController constructor.
|
||||||
*
|
*
|
||||||
* @param \Pterodactyl\Services\Servers\ContainerRebuildService $rebuildService
|
|
||||||
* @param \Pterodactyl\Services\Servers\ReinstallServerService $reinstallServerService
|
* @param \Pterodactyl\Services\Servers\ReinstallServerService $reinstallServerService
|
||||||
* @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService
|
* @param \Pterodactyl\Services\Servers\SuspensionService $suspensionService
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ContainerRebuildService $rebuildService,
|
|
||||||
ReinstallServerService $reinstallServerService,
|
ReinstallServerService $reinstallServerService,
|
||||||
SuspensionService $suspensionService
|
SuspensionService $suspensionService
|
||||||
) {
|
) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->rebuildService = $rebuildService;
|
|
||||||
$this->reinstallServerService = $reinstallServerService;
|
$this->reinstallServerService = $reinstallServerService;
|
||||||
$this->suspensionService = $suspensionService;
|
$this->suspensionService = $suspensionService;
|
||||||
}
|
}
|
||||||
|
@ -53,9 +44,7 @@ class ServerManagementController extends ApplicationApiController
|
||||||
* @param \Pterodactyl\Models\Server $server
|
* @param \Pterodactyl\Models\Server $server
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws \Throwable
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public function suspend(ServerWriteRequest $request, Server $server): Response
|
public function suspend(ServerWriteRequest $request, Server $server): Response
|
||||||
{
|
{
|
||||||
|
@ -71,9 +60,7 @@ class ServerManagementController extends ApplicationApiController
|
||||||
* @param \Pterodactyl\Models\Server $server
|
* @param \Pterodactyl\Models\Server $server
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*
|
*
|
||||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
* @throws \Throwable
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
|
||||||
*/
|
*/
|
||||||
public function unsuspend(ServerWriteRequest $request, Server $server): Response
|
public function unsuspend(ServerWriteRequest $request, Server $server): Response
|
||||||
{
|
{
|
||||||
|
@ -99,20 +86,4 @@ class ServerManagementController extends ApplicationApiController
|
||||||
|
|
||||||
return $this->returnNoContent();
|
return $this->returnNoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark a server as needing its container rebuilt the next time it is started.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Http\Requests\Api\Application\Servers\ServerWriteRequest $request
|
|
||||||
* @param \Pterodactyl\Models\Server $server
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
*/
|
|
||||||
public function rebuild(ServerWriteRequest $request, Server $server): Response
|
|
||||||
{
|
|
||||||
$this->rebuildService->handle($server);
|
|
||||||
|
|
||||||
return $this->returnNoContent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,9 +107,10 @@ class BuildModificationService
|
||||||
$updateData = $this->structureService->handle($server);
|
$updateData = $this->structureService->handle($server);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->daemonServerRepository->setServer($server)->update(
|
$this->daemonServerRepository
|
||||||
Arr::only($updateData, ['allocations', 'build', 'container'])
|
->setServer($server)
|
||||||
);
|
->update(Arr::only($updateData, ['build']));
|
||||||
|
|
||||||
$this->connection->commit();
|
$this->connection->commit();
|
||||||
} catch (RequestException $exception) {
|
} catch (RequestException $exception) {
|
||||||
throw new DaemonConnectionException($exception);
|
throw new DaemonConnectionException($exception);
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Pterodactyl\Services\Servers;
|
|
||||||
|
|
||||||
use Pterodactyl\Models\Server;
|
|
||||||
use GuzzleHttp\Exception\RequestException;
|
|
||||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
|
||||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|
||||||
|
|
||||||
class ContainerRebuildService
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
|
||||||
*/
|
|
||||||
private $repository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ContainerRebuildService constructor.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $repository
|
|
||||||
*/
|
|
||||||
public function __construct(DaemonServerRepository $repository)
|
|
||||||
{
|
|
||||||
$this->repository = $repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mark a server for rebuild on next boot cycle. This just makes an empty patch
|
|
||||||
* request to Wings which will automatically mark the container as requiring a rebuild
|
|
||||||
* on the next boot as a result.
|
|
||||||
*
|
|
||||||
* @param \Pterodactyl\Models\Server $server
|
|
||||||
*
|
|
||||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
*/
|
|
||||||
public function handle(Server $server)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->repository->setServer($server)->update([]);
|
|
||||||
} catch (RequestException $exception) {
|
|
||||||
throw new DaemonConnectionException($exception);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,16 +2,12 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Services\Servers;
|
namespace Pterodactyl\Services\Servers;
|
||||||
|
|
||||||
use Illuminate\Support\Arr;
|
|
||||||
use Pterodactyl\Models\User;
|
use Pterodactyl\Models\User;
|
||||||
use Pterodactyl\Models\Server;
|
use Pterodactyl\Models\Server;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
|
||||||
use Illuminate\Database\ConnectionInterface;
|
use Illuminate\Database\ConnectionInterface;
|
||||||
use Pterodactyl\Traits\Services\HasUserLevels;
|
use Pterodactyl\Traits\Services\HasUserLevels;
|
||||||
use Pterodactyl\Repositories\Wings\DaemonServerRepository;
|
|
||||||
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\EggRepositoryInterface;
|
||||||
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
|
||||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
|
||||||
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
use Pterodactyl\Contracts\Repository\ServerVariableRepositoryInterface;
|
||||||
|
|
||||||
class StartupModificationService
|
class StartupModificationService
|
||||||
|
@ -48,11 +44,6 @@ class StartupModificationService
|
||||||
*/
|
*/
|
||||||
private $validatorService;
|
private $validatorService;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Repositories\Wings\DaemonServerRepository
|
|
||||||
*/
|
|
||||||
private $daemonServerRepository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
* @var \Pterodactyl\Services\Servers\ServerConfigurationStructureService
|
||||||
*/
|
*/
|
||||||
|
@ -62,7 +53,6 @@ class StartupModificationService
|
||||||
* StartupModificationService constructor.
|
* StartupModificationService constructor.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||||
* @param \Pterodactyl\Repositories\Wings\DaemonServerRepository $daemonServerRepository
|
|
||||||
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository
|
* @param \Pterodactyl\Contracts\Repository\EggRepositoryInterface $eggRepository
|
||||||
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
|
* @param \Pterodactyl\Services\Servers\EnvironmentService $environmentService
|
||||||
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
* @param \Pterodactyl\Contracts\Repository\ServerRepositoryInterface $repository
|
||||||
|
@ -72,7 +62,6 @@ class StartupModificationService
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ConnectionInterface $connection,
|
ConnectionInterface $connection,
|
||||||
DaemonServerRepository $daemonServerRepository,
|
|
||||||
EggRepositoryInterface $eggRepository,
|
EggRepositoryInterface $eggRepository,
|
||||||
EnvironmentService $environmentService,
|
EnvironmentService $environmentService,
|
||||||
ServerRepositoryInterface $repository,
|
ServerRepositoryInterface $repository,
|
||||||
|
@ -86,7 +75,6 @@ class StartupModificationService
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->serverVariableRepository = $serverVariableRepository;
|
$this->serverVariableRepository = $serverVariableRepository;
|
||||||
$this->validatorService = $validatorService;
|
$this->validatorService = $validatorService;
|
||||||
$this->daemonServerRepository = $daemonServerRepository;
|
|
||||||
$this->structureService = $structureService;
|
$this->structureService = $structureService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +86,6 @@ class StartupModificationService
|
||||||
* @return \Pterodactyl\Models\Server
|
* @return \Pterodactyl\Models\Server
|
||||||
*
|
*
|
||||||
* @throws \Illuminate\Validation\ValidationException
|
* @throws \Illuminate\Validation\ValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||||
*/
|
*/
|
||||||
|
@ -123,17 +110,6 @@ class StartupModificationService
|
||||||
$this->updateAdministrativeSettings($data, $server);
|
$this->updateAdministrativeSettings($data, $server);
|
||||||
}
|
}
|
||||||
|
|
||||||
$updateData = $this->structureService->handle($server);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->daemonServerRepository->setServer($server)->update(
|
|
||||||
Arr::only($updateData, ['environment', 'invocation', 'service'])
|
|
||||||
);
|
|
||||||
} catch (RequestException $exception) {
|
|
||||||
$this->connection->rollBack();
|
|
||||||
throw new DaemonConnectionException($exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->connection->commit();
|
$this->connection->commit();
|
||||||
|
|
||||||
return $server;
|
return $server;
|
||||||
|
|
|
@ -123,7 +123,6 @@ Route::group(['prefix' => 'servers'], function () {
|
||||||
Route::post('/view/{server}/startup', 'ServersController@saveStartup');
|
Route::post('/view/{server}/startup', 'ServersController@saveStartup');
|
||||||
Route::post('/view/{server}/database', 'ServersController@newDatabase');
|
Route::post('/view/{server}/database', 'ServersController@newDatabase');
|
||||||
Route::post('/view/{server}/manage/toggle', 'ServersController@toggleInstall')->name('admin.servers.view.manage.toggle');
|
Route::post('/view/{server}/manage/toggle', 'ServersController@toggleInstall')->name('admin.servers.view.manage.toggle');
|
||||||
Route::post('/view/{server}/manage/rebuild', 'ServersController@rebuildContainer')->name('admin.servers.view.manage.rebuild');
|
|
||||||
Route::post('/view/{server}/manage/suspension', 'ServersController@manageSuspension')->name('admin.servers.view.manage.suspension');
|
Route::post('/view/{server}/manage/suspension', 'ServersController@manageSuspension')->name('admin.servers.view.manage.suspension');
|
||||||
Route::post('/view/{server}/manage/reinstall', 'ServersController@reinstallServer')->name('admin.servers.view.manage.reinstall');
|
Route::post('/view/{server}/manage/reinstall', 'ServersController@reinstallServer')->name('admin.servers.view.manage.reinstall');
|
||||||
Route::post('/view/{server}/delete', 'ServersController@delete');
|
Route::post('/view/{server}/delete', 'ServersController@delete');
|
||||||
|
|
|
@ -84,7 +84,6 @@ Route::group(['prefix' => '/servers'], function () {
|
||||||
Route::post('/{server}/suspend', 'Servers\ServerManagementController@suspend')->name('api.application.servers.suspend');
|
Route::post('/{server}/suspend', 'Servers\ServerManagementController@suspend')->name('api.application.servers.suspend');
|
||||||
Route::post('/{server}/unsuspend', 'Servers\ServerManagementController@unsuspend')->name('api.application.servers.unsuspend');
|
Route::post('/{server}/unsuspend', 'Servers\ServerManagementController@unsuspend')->name('api.application.servers.unsuspend');
|
||||||
Route::post('/{server}/reinstall', 'Servers\ServerManagementController@reinstall')->name('api.application.servers.reinstall');
|
Route::post('/{server}/reinstall', 'Servers\ServerManagementController@reinstall')->name('api.application.servers.reinstall');
|
||||||
Route::post('/{server}/rebuild', 'Servers\ServerManagementController@rebuild')->name('api.application.servers.rebuild');
|
|
||||||
|
|
||||||
Route::delete('/{server}', 'Servers\ServerController@delete');
|
Route::delete('/{server}', 'Servers\ServerController@delete');
|
||||||
Route::delete('/{server}/{force?}', 'Servers\ServerController@delete');
|
Route::delete('/{server}/{force?}', 'Servers\ServerController@delete');
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\Services\Servers;
|
|
||||||
|
|
||||||
use Mockery as m;
|
|
||||||
use Tests\TestCase;
|
|
||||||
use GuzzleHttp\Psr7\Response;
|
|
||||||
use Pterodactyl\Models\Server;
|
|
||||||
use GuzzleHttp\Exception\RequestException;
|
|
||||||
use Pterodactyl\Services\Servers\ContainerRebuildService;
|
|
||||||
use Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface;
|
|
||||||
|
|
||||||
class ContainerRebuildServiceTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Contracts\Repository\Daemon\ServerRepositoryInterface|\Mockery\Mock
|
|
||||||
*/
|
|
||||||
protected $repository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \GuzzleHttp\Exception\RequestException
|
|
||||||
*/
|
|
||||||
protected $exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Models\Server
|
|
||||||
*/
|
|
||||||
protected $server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Pterodactyl\Services\Servers\ContainerRebuildService
|
|
||||||
*/
|
|
||||||
protected $service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup tests.
|
|
||||||
*/
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->exception = m::mock(RequestException::class)->makePartial();
|
|
||||||
$this->repository = m::mock(ServerRepositoryInterface::class);
|
|
||||||
|
|
||||||
$this->server = factory(Server::class)->make(['node_id' => 1]);
|
|
||||||
$this->service = new ContainerRebuildService($this->repository);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that a server is marked for rebuild.
|
|
||||||
*/
|
|
||||||
public function testServerIsMarkedForRebuild()
|
|
||||||
{
|
|
||||||
$this->repository->shouldReceive('setServer')->with($this->server)->once()->andReturnSelf()
|
|
||||||
->shouldReceive('rebuild')->withNoArgs()->once()->andReturn(new Response);
|
|
||||||
|
|
||||||
$this->service->handle($this->server);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test that an exception thrown by guzzle is rendered as a displayable exception.
|
|
||||||
*
|
|
||||||
* @expectedException \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException
|
|
||||||
*/
|
|
||||||
public function testExceptionThrownByGuzzle()
|
|
||||||
{
|
|
||||||
$this->repository->shouldReceive('setServer')->with($this->server)->once()->andThrow($this->exception);
|
|
||||||
|
|
||||||
$this->service->handle($this->server);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue