Set out some roach traps to catch all these 🐛

This commit is contained in:
Dane Everitt 2017-02-16 13:56:28 -05:00
parent 336234843d
commit 2e134b7a55
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
8 changed files with 24 additions and 25 deletions

View file

@ -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();
}
/**

View file

@ -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();

View file

@ -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) {

View file

@ -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.',

View file

@ -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]

View file

@ -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();
}

View file

@ -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_<env_variable>)
$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,
]);
}

View file

@ -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)) {