From 032e4f2e31a9de60be734702d1f158ef8d07ebf6 Mon Sep 17 00:00:00 2001 From: Boy132 Date: Mon, 7 Nov 2022 00:02:30 +0100 Subject: [PATCH] Apply node maintenance mode to servers (#4421) --- .../Http/Server/ServerStateConflictException.php | 2 ++ .../Api/Client/Server/AuthenticateServerAccess.php | 2 +- .../Requests/Api/Application/Nodes/StoreNodeRequest.php | 1 + app/Models/Node.php | 5 +++++ app/Models/Server.php | 1 + app/Transformers/Api/Client/ServerTransformer.php | 1 + resources/scripts/api/server/getServer.ts | 2 ++ .../scripts/components/server/ConflictStateRenderer.tsx | 9 +++++++++ .../components/server/console/ServerConsoleContainer.tsx | 7 +++++-- resources/scripts/state/server/index.ts | 2 +- resources/views/admin/nodes/view/index.blade.php | 2 +- 11 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/Exceptions/Http/Server/ServerStateConflictException.php b/app/Exceptions/Http/Server/ServerStateConflictException.php index f0eb096b1..ea6a60a55 100644 --- a/app/Exceptions/Http/Server/ServerStateConflictException.php +++ b/app/Exceptions/Http/Server/ServerStateConflictException.php @@ -17,6 +17,8 @@ class ServerStateConflictException extends ConflictHttpException $message = 'This server is currently in an unsupported state, please try again later.'; if ($server->isSuspended()) { $message = 'This server is currently suspended and the functionality requested is unavailable.'; + } elseif ($server->node->isUnderMaintenance()) { + $message = 'The node of this server is currently under maintenance and the functionality requested is unavailable.'; } elseif (!$server->isInstalled()) { $message = 'This server has not yet completed its installation process, please try again later.'; } elseif ($server->status === Server::STATUS_RESTORING_BACKUP) { diff --git a/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php b/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php index 40a4d0cf1..358fb6d57 100644 --- a/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php +++ b/app/Http/Middleware/Api/Client/Server/AuthenticateServerAccess.php @@ -53,7 +53,7 @@ class AuthenticateServerAccess // Still allow users to get information about their server if it is installing or // being transferred. if (!$request->routeIs('api:client:server.view')) { - if ($server->isSuspended() && !$request->routeIs('api:client:server.resources')) { + if (($server->isSuspended() || $server->node->isUnderMaintenance()) && !$request->routeIs('api:client:server.resources')) { throw $exception; } if (!$user->root_admin || !$request->routeIs($this->except)) { diff --git a/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php b/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php index bc559083e..4fe705448 100644 --- a/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php +++ b/app/Http/Requests/Api/Application/Nodes/StoreNodeRequest.php @@ -24,6 +24,7 @@ class StoreNodeRequest extends ApplicationApiRequest 'fqdn', 'scheme', 'behind_proxy', + 'maintenance_mode', 'memory', 'memory_overallocate', 'disk', diff --git a/app/Models/Node.php b/app/Models/Node.php index 37aec760d..62ec82871 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -186,6 +186,11 @@ class Node extends Model ); } + public function isUnderMaintenance(): bool + { + return $this->maintenance_mode; + } + public function mounts(): HasManyThrough { return $this->hasManyThrough(Mount::class, MountNode::class, 'node_id', 'id', 'id', 'mount_id'); diff --git a/app/Models/Server.php b/app/Models/Server.php index 5ad99151a..d7cc649c0 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -354,6 +354,7 @@ class Server extends Model { if ( $this->isSuspended() || + $this->node->isUnderMaintenance() || !$this->isInstalled() || $this->status === self::STATUS_RESTORING_BACKUP || !is_null($this->transfer) diff --git a/app/Transformers/Api/Client/ServerTransformer.php b/app/Transformers/Api/Client/ServerTransformer.php index 8ae4ed4a6..9f7bce958 100644 --- a/app/Transformers/Api/Client/ServerTransformer.php +++ b/app/Transformers/Api/Client/ServerTransformer.php @@ -43,6 +43,7 @@ class ServerTransformer extends BaseClientTransformer 'uuid' => $server->uuid, 'name' => $server->name, 'node' => $server->node->name, + 'is_node_under_maintenance' => $server->node->isUnderMaintenance(), 'sftp_details' => [ 'ip' => $server->node->fqdn, 'port' => $server->node->daemonSFTP, diff --git a/resources/scripts/api/server/getServer.ts b/resources/scripts/api/server/getServer.ts index 5ed92a427..d2aa2e054 100644 --- a/resources/scripts/api/server/getServer.ts +++ b/resources/scripts/api/server/getServer.ts @@ -17,6 +17,7 @@ export interface Server { uuid: string; name: string; node: string; + isNodeUnderMaintenance: boolean; status: ServerStatus; sftpDetails: { ip: string; @@ -50,6 +51,7 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData) uuid: data.uuid, name: data.name, node: data.node, + isNodeUnderMaintenance: data.is_node_under_maintenance, status: data.status, invocation: data.invocation, dockerImage: data.docker_image, diff --git a/resources/scripts/components/server/ConflictStateRenderer.tsx b/resources/scripts/components/server/ConflictStateRenderer.tsx index 70475a4ee..95e70bbaa 100644 --- a/resources/scripts/components/server/ConflictStateRenderer.tsx +++ b/resources/scripts/components/server/ConflictStateRenderer.tsx @@ -8,6 +8,9 @@ import ServerRestoreSvg from '@/assets/images/server_restore.svg'; export default () => { const status = ServerContext.useStoreState((state) => state.server.data?.status || null); const isTransferring = ServerContext.useStoreState((state) => state.server.data?.isTransferring || false); + const isNodeUnderMaintenance = ServerContext.useStoreState( + (state) => state.server.data?.isNodeUnderMaintenance || false + ); return status === 'installing' || status === 'install_failed' ? ( { image={ServerErrorSvg} message={'This server is suspended and cannot be accessed.'} /> + ) : isNodeUnderMaintenance ? ( + ) : ( { const isInstalling = ServerContext.useStoreState((state) => state.server.isInstalling); const isTransferring = ServerContext.useStoreState((state) => state.server.data!.isTransferring); const eggFeatures = ServerContext.useStoreState((state) => state.server.data!.eggFeatures, isEqual); + const isNodeUnderMaintenance = ServerContext.useStoreState((state) => state.server.data!.isNodeUnderMaintenance); return ( - {(isInstalling || isTransferring) && ( + {(isNodeUnderMaintenance || isInstalling || isTransferring) && ( - {isInstalling + {isNodeUnderMaintenance + ? 'The node of this server is currently under maintenance and all actions are unavailable.' + : isInstalling ? 'This server is currently running its installation process and most actions are unavailable.' : 'This server is currently being transferred to another node and all actions are unavailable.'} diff --git a/resources/scripts/state/server/index.ts b/resources/scripts/state/server/index.ts index 8d8eba749..f9806b649 100644 --- a/resources/scripts/state/server/index.ts +++ b/resources/scripts/state/server/index.ts @@ -30,7 +30,7 @@ const server: ServerDataStore = { return false; } - return state.data.status !== null || state.data.isTransferring; + return state.data.status !== null || state.data.isTransferring || state.data.isNodeUnderMaintenance; }), isInstalling: computed((state) => { diff --git a/resources/views/admin/nodes/view/index.blade.php b/resources/views/admin/nodes/view/index.blade.php index 9ef461076..ce90b30b2 100644 --- a/resources/views/admin/nodes/view/index.blade.php +++ b/resources/views/admin/nodes/view/index.blade.php @@ -93,7 +93,7 @@
@if($node->maintenance_mode)
-
+
This node is under