Set out some roach traps to catch all these 🐛
This commit is contained in:
parent
336234843d
commit
2e134b7a55
8 changed files with 24 additions and 25 deletions
|
@ -187,7 +187,7 @@ class NodeController extends BaseController
|
||||||
*/
|
*/
|
||||||
public function allocationsView(Request $request, $id)
|
public function allocationsView(Request $request, $id)
|
||||||
{
|
{
|
||||||
return Models\Allocation::where('assigned_to', $id)->get()->toArray();
|
return Models\Allocation::where('server_id', $id)->get()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -159,7 +159,7 @@ class NodesController extends Controller
|
||||||
|
|
||||||
public function deallocateSingle(Request $request, $node, $allocation)
|
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) {
|
if ((int) $query === 0) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'error' => 'Unable to find an allocation matching those details to delete.',
|
'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)
|
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) {
|
if ((int) $query === 0) {
|
||||||
Alert::danger('There was an error while attempting to delete allocations on that IP.')->flash();
|
Alert::danger('There was an error while attempting to delete allocations on that IP.')->flash();
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ class ServersController extends Controller
|
||||||
], 500);
|
], 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);
|
], 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 = [];
|
$listing = [];
|
||||||
|
|
||||||
foreach ($ips as &$ip) {
|
foreach ($ips as &$ip) {
|
||||||
|
|
|
@ -181,7 +181,7 @@ class AjaxController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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) {
|
if (! $allocation) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'error' => 'No allocation matching your request was found in the system.',
|
'error' => 'No allocation matching your request was found in the system.',
|
||||||
|
|
|
@ -37,7 +37,7 @@ class ServerObserver
|
||||||
use DispatchesJobs;
|
use DispatchesJobs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen to the Server deleted event.
|
* Listen to the Server creating event.
|
||||||
*
|
*
|
||||||
* @param Server $server [description]
|
* @param Server $server [description]
|
||||||
* @return [type] [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]
|
* @param Server $server [description]
|
||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
|
@ -58,20 +58,18 @@ class ServerObserver
|
||||||
event(new Events\Server\Created($server));
|
event(new Events\Server\Created($server));
|
||||||
|
|
||||||
// Queue Notification Email
|
// Queue Notification Email
|
||||||
$server->load('user', 'node', 'service.option');
|
|
||||||
|
|
||||||
$server->user->notify((new ServerCreated([
|
$server->user->notify((new ServerCreated([
|
||||||
'name' => $server->name,
|
'name' => $server->name,
|
||||||
'memory' => $server->memory,
|
'memory' => $server->memory,
|
||||||
'node' => $server->node->name,
|
'node' => $server->node->name,
|
||||||
'service' => $server->service->name,
|
'service' => $server->service->name,
|
||||||
'option' => $server->service->option->name,
|
'option' => $server->option->name,
|
||||||
'uuidShort' => $server->uuidShort,
|
'uuidShort' => $server->uuidShort,
|
||||||
])));
|
])));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen to the Server deleted event.
|
* Listen to the Server deleting event.
|
||||||
*
|
*
|
||||||
* @param Server $server [description]
|
* @param Server $server [description]
|
||||||
* @return [type] [description]
|
* @return [type] [description]
|
||||||
|
|
|
@ -220,7 +220,7 @@ class NodeRepository
|
||||||
'ip' => $ip,
|
'ip' => $ip,
|
||||||
'port' => $assignPort,
|
'port' => $assignPort,
|
||||||
'ip_alias' => $setAlias,
|
'ip_alias' => $setAlias,
|
||||||
'assigned_to' => null,
|
'server_id' => null,
|
||||||
]);
|
]);
|
||||||
$alloc->save();
|
$alloc->save();
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ class NodeRepository
|
||||||
'ip' => $ip,
|
'ip' => $ip,
|
||||||
'port' => $port,
|
'port' => $port,
|
||||||
'ip_alias' => $setAlias,
|
'ip_alias' => $setAlias,
|
||||||
'assigned_to' => null,
|
'server_id' => null,
|
||||||
]);
|
]);
|
||||||
$alloc->save();
|
$alloc->save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,10 +144,11 @@ class ServerRepository
|
||||||
// We know the node exists because of 'exists:nodes,id' in the validation
|
// We know the node exists because of 'exists:nodes,id' in the validation
|
||||||
if (! $autoDeployed) {
|
if (! $autoDeployed) {
|
||||||
if (! isset($data['allocation_id'])) {
|
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 {
|
} 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.
|
// 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 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
|
// 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>)
|
// 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) {
|
if (! $option) {
|
||||||
throw new DisplayException('The requested service option does not exist for the specified service.');
|
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'])) {
|
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) {
|
if (! $pack) {
|
||||||
throw new DisplayException('The requested service pack does not seem to exist for this combination.');
|
throw new DisplayException('The requested service pack does not seem to exist for this combination.');
|
||||||
}
|
}
|
||||||
|
@ -264,7 +265,7 @@ class ServerRepository
|
||||||
'io' => $data['io'],
|
'io' => $data['io'],
|
||||||
'cpu' => $data['cpu'],
|
'cpu' => $data['cpu'],
|
||||||
'oom_disabled' => (isset($data['oom_disabled'])) ? true : false,
|
'oom_disabled' => (isset($data['oom_disabled'])) ? true : false,
|
||||||
'allocation' => $allocation->id,
|
'allocation_id' => $allocation->id,
|
||||||
'service_id' => $data['service_id'],
|
'service_id' => $data['service_id'],
|
||||||
'option_id' => $data['option_id'],
|
'option_id' => $data['option_id'],
|
||||||
'pack_id' => $data['pack_id'],
|
'pack_id' => $data['pack_id'],
|
||||||
|
@ -540,7 +541,7 @@ class ServerRepository
|
||||||
|
|
||||||
$newPorts = true;
|
$newPorts = true;
|
||||||
$server->allocations->where('ip', $ip)->where('port', $port)->update([
|
$server->allocations->where('ip', $ip)->where('port', $port)->update([
|
||||||
'assigned_to' => null,
|
'server_id' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,8 +563,8 @@ class ServerRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
$newPorts = true;
|
$newPorts = true;
|
||||||
Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('assigned_to')->update([
|
Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('server_id')->update([
|
||||||
'assigned_to' => $server->id,
|
'server_id' => $server->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ class DeploymentService
|
||||||
throw new DisplayException('The location passed was not valid and could not be found.');
|
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) {
|
if (! $node) {
|
||||||
throw new DisplayException("Unable to find a node in location {$useLocation->short} (id: {$useLocation->id}) that is available and has space.");
|
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)
|
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) {
|
if (! $allocation) {
|
||||||
throw new DisplayException('No available allocation could be found for the assigned node.');
|
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)
|
protected static function checkNodeAllocation(Models\Node $node, $memory, $disk)
|
||||||
{
|
{
|
||||||
if (is_numeric($node->memory_overallocate) || is_numeric($node->disk_overallocate)) {
|
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
|
// Check memory limits
|
||||||
if (is_numeric($node->memory_overallocate)) {
|
if (is_numeric($node->memory_overallocate)) {
|
||||||
|
|
Loading…
Reference in a new issue