From 2e134b7a555b0681d3dec7b0cb42b8c014abba39 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 16 Feb 2017 13:56:28 -0500 Subject: [PATCH] Set out some roach traps to catch all these :bug: --- app/Http/Controllers/API/NodeController.php | 2 +- app/Http/Controllers/Admin/NodesController.php | 4 ++-- .../Controllers/Admin/ServersController.php | 4 ++-- app/Http/Controllers/Server/AjaxController.php | 2 +- app/Observers/ServerObserver.php | 10 ++++------ app/Repositories/NodeRepository.php | 4 ++-- app/Repositories/ServerRepository.php | 17 +++++++++-------- app/Services/DeploymentService.php | 6 +++--- 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/API/NodeController.php b/app/Http/Controllers/API/NodeController.php index ce76e4637..b0cfb452a 100755 --- a/app/Http/Controllers/API/NodeController.php +++ b/app/Http/Controllers/API/NodeController.php @@ -187,7 +187,7 @@ class NodeController extends BaseController */ public function allocationsView(Request $request, $id) { - return Models\Allocation::where('assigned_to', $id)->get()->toArray(); + return Models\Allocation::where('server_id', $id)->get()->toArray(); } /** diff --git a/app/Http/Controllers/Admin/NodesController.php b/app/Http/Controllers/Admin/NodesController.php index fc32f3929..d2eca4626 100644 --- a/app/Http/Controllers/Admin/NodesController.php +++ b/app/Http/Controllers/Admin/NodesController.php @@ -159,7 +159,7 @@ class NodesController extends Controller public function deallocateSingle(Request $request, $node, $allocation) { - $query = Models\Allocation::where('node', $node)->whereNull('assigned_to')->where('id', $allocation)->delete(); + $query = Models\Allocation::where('node', $node)->whereNull('server_id')->where('id', $allocation)->delete(); if ((int) $query === 0) { return response()->json([ 'error' => 'Unable to find an allocation matching those details to delete.', @@ -171,7 +171,7 @@ class NodesController extends Controller public function deallocateBlock(Request $request, $node) { - $query = Models\Allocation::where('node', $node)->whereNull('assigned_to')->where('ip', $request->input('ip'))->delete(); + $query = Models\Allocation::where('node', $node)->whereNull('server_id')->where('ip', $request->input('ip'))->delete(); if ((int) $query === 0) { Alert::danger('There was an error while attempting to delete allocations on that IP.')->flash(); diff --git a/app/Http/Controllers/Admin/ServersController.php b/app/Http/Controllers/Admin/ServersController.php index e494e8e56..0f5cf495d 100644 --- a/app/Http/Controllers/Admin/ServersController.php +++ b/app/Http/Controllers/Admin/ServersController.php @@ -115,7 +115,7 @@ class ServersController extends Controller ], 500); } - return response()->json(Models\Node::select('id', 'name', 'public')->where('location', $request->input('location'))->get()); + return response()->json(Models\Node::select('id', 'name', 'public')->where('location_id', $request->input('location'))->get()); } /** @@ -132,7 +132,7 @@ class ServersController extends Controller ], 500); } - $ips = Models\Allocation::where('node', $request->input('node'))->whereNull('assigned_to')->get(); + $ips = Models\Allocation::where('node_id', $request->input('node'))->whereNull('server_id')->get(); $listing = []; foreach ($ips as &$ip) { diff --git a/app/Http/Controllers/Server/AjaxController.php b/app/Http/Controllers/Server/AjaxController.php index 9493bc0f0..d18aee7bf 100644 --- a/app/Http/Controllers/Server/AjaxController.php +++ b/app/Http/Controllers/Server/AjaxController.php @@ -181,7 +181,7 @@ class AjaxController extends Controller } try { - $allocation = $server->allocations->where('id', $request->input('allocation'))->where('assigned_to', $server->id)->first(); + $allocation = $server->allocations->where('id', $request->input('allocation'))->where('server_id', $server->id)->first(); if (! $allocation) { return response()->json([ 'error' => 'No allocation matching your request was found in the system.', diff --git a/app/Observers/ServerObserver.php b/app/Observers/ServerObserver.php index e4b00e000..06778c674 100644 --- a/app/Observers/ServerObserver.php +++ b/app/Observers/ServerObserver.php @@ -37,7 +37,7 @@ class ServerObserver use DispatchesJobs; /** - * Listen to the Server deleted event. + * Listen to the Server creating event. * * @param Server $server [description] * @return [type] [description] @@ -48,7 +48,7 @@ class ServerObserver } /** - * Listen to the Server deleted event. + * Listen to the Server created event. * * @param Server $server [description] * @return [type] [description] @@ -58,20 +58,18 @@ class ServerObserver event(new Events\Server\Created($server)); // Queue Notification Email - $server->load('user', 'node', 'service.option'); - $server->user->notify((new ServerCreated([ 'name' => $server->name, 'memory' => $server->memory, 'node' => $server->node->name, 'service' => $server->service->name, - 'option' => $server->service->option->name, + 'option' => $server->option->name, 'uuidShort' => $server->uuidShort, ]))); } /** - * Listen to the Server deleted event. + * Listen to the Server deleting event. * * @param Server $server [description] * @return [type] [description] diff --git a/app/Repositories/NodeRepository.php b/app/Repositories/NodeRepository.php index 1af316b23..c0d85adf5 100644 --- a/app/Repositories/NodeRepository.php +++ b/app/Repositories/NodeRepository.php @@ -220,7 +220,7 @@ class NodeRepository 'ip' => $ip, 'port' => $assignPort, 'ip_alias' => $setAlias, - 'assigned_to' => null, + 'server_id' => null, ]); $alloc->save(); } @@ -237,7 +237,7 @@ class NodeRepository 'ip' => $ip, 'port' => $port, 'ip_alias' => $setAlias, - 'assigned_to' => null, + 'server_id' => null, ]); $alloc->save(); } diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 37c18a058..fd54649c9 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -144,10 +144,11 @@ class ServerRepository // We know the node exists because of 'exists:nodes,id' in the validation if (! $autoDeployed) { if (! isset($data['allocation_id'])) { - $allocation = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port'])->where('node', $data['node'])->whereNull('assigned_to')->first(); + $model = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port']); } else { - $allocation = Models\Allocation::where('id', $data['allocation'])->where('node', $data['node'])->whereNull('assigned_to')->first(); + $model = Models\Allocation::where('id', $data['allocation_id']); } + $allocation = $model->where('node_id', $data['node_id'])->whereNull('server_id')->first(); } // Something failed in the query, either that combo doesn't exist, or it is in use. @@ -159,7 +160,7 @@ class ServerRepository // We know the service and option exists because of the validation. // We need to verify that the option exists for the service, and then check for // any required variable fields. (fields are labeled env_) - $option = Models\ServiceOption::where('id', $data['option'])->where('service_id', $data['service'])->first(); + $option = Models\ServiceOption::where('id', $data['option_id'])->where('service_id', $data['service_id'])->first(); if (! $option) { throw new DisplayException('The requested service option does not exist for the specified service.'); } @@ -170,7 +171,7 @@ class ServerRepository } if (! is_null($data['pack_id'])) { - $pack = Models\ServicePack::where('id', $data['pack_id'])->where('option', $data['option_id'])->first(); + $pack = Models\ServicePack::where('id', $data['pack_id'])->where('option_id', $data['option_id'])->first(); if (! $pack) { throw new DisplayException('The requested service pack does not seem to exist for this combination.'); } @@ -264,7 +265,7 @@ class ServerRepository 'io' => $data['io'], 'cpu' => $data['cpu'], 'oom_disabled' => (isset($data['oom_disabled'])) ? true : false, - 'allocation' => $allocation->id, + 'allocation_id' => $allocation->id, 'service_id' => $data['service_id'], 'option_id' => $data['option_id'], 'pack_id' => $data['pack_id'], @@ -540,7 +541,7 @@ class ServerRepository $newPorts = true; $server->allocations->where('ip', $ip)->where('port', $port)->update([ - 'assigned_to' => null, + 'server_id' => null, ]); } @@ -562,8 +563,8 @@ class ServerRepository } $newPorts = true; - Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('assigned_to')->update([ - 'assigned_to' => $server->id, + Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('server_id')->update([ + 'server_id' => $server->id, ]); } diff --git a/app/Services/DeploymentService.php b/app/Services/DeploymentService.php index 5f2a99473..af1ede940 100644 --- a/app/Services/DeploymentService.php +++ b/app/Services/DeploymentService.php @@ -65,7 +65,7 @@ class DeploymentService throw new DisplayException('The location passed was not valid and could not be found.'); } - $node = Models\Node::where('location', $useLocation->id)->where('public', 1)->whereNotIn('id', $not)->inRandomOrder()->first(); + $node = Models\Node::where('location_id', $useLocation->id)->where('public', 1)->whereNotIn('id', $not)->inRandomOrder()->first(); if (! $node) { throw new DisplayException("Unable to find a node in location {$useLocation->short} (id: {$useLocation->id}) that is available and has space."); } @@ -107,7 +107,7 @@ class DeploymentService */ public static function randomAllocation($node) { - $allocation = Models\Allocation::where('node', $node)->whereNull('assigned_to')->inRandomOrder()->first(); + $allocation = Models\Allocation::where('node_id', $node)->whereNull('server_id')->inRandomOrder()->first(); if (! $allocation) { throw new DisplayException('No available allocation could be found for the assigned node.'); } @@ -125,7 +125,7 @@ class DeploymentService protected static function checkNodeAllocation(Models\Node $node, $memory, $disk) { if (is_numeric($node->memory_overallocate) || is_numeric($node->disk_overallocate)) { - $totals = Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node', $node->id)->first(); + $totals = Models\Server::select(DB::raw('SUM(memory) as memory, SUM(disk) as disk'))->where('node_id', $node->id)->first(); // Check memory limits if (is_numeric($node->memory_overallocate)) {