Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply node maintenance mode to servers #4421

Merged
merged 12 commits into from
Nov 6, 2022
2 changes: 2 additions & 0 deletions app/Exceptions/Http/Server/ServerStateConflictException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function __construct(Server $server, Throwable $previous = null)
$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->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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function handle(Request $request, Closure $next): mixed
// 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->isUnderMaintenance()) && !$request->routeIs('api:client:server.resources')) {
throw $exception;
}
if (!$user->root_admin || !$request->routeIs($this->except)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function rules(array $rules = null): array
'fqdn',
'scheme',
'behind_proxy',
'maintenance_mode',
'memory',
'memory_overallocate',
'disk',
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public function isSuspended(): bool
return $this->status === self::STATUS_SUSPENDED;
}

public function isUnderMaintenance(): bool
Boy132 marked this conversation as resolved.
Show resolved Hide resolved
{
return $this->node->maintenance_mode;
}

/**
* Gets the user who owns the server.
*/
Expand Down Expand Up @@ -354,6 +359,7 @@ public function validateCurrentState()
{
if (
$this->isSuspended() ||
$this->isUnderMaintenance() ||
!$this->isInstalled() ||
$this->status === self::STATUS_RESTORING_BACKUP ||
!is_null($this->transfer)
Expand Down
5 changes: 4 additions & 1 deletion app/Transformers/Api/Client/ServerTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public function transform(Server $server): array
'internal_id' => $server->id,
'uuid' => $server->uuid,
'name' => $server->name,
'node' => $server->node->name,
'node' => [
Boy132 marked this conversation as resolved.
Show resolved Hide resolved
'name' => $server->node->name,
'maintenance_mode' => $server->node->maintenance_mode,
],
'sftp_details' => [
'ip' => $server->node->fqdn,
'port' => $server->node->daemonSFTP,
Expand Down
10 changes: 8 additions & 2 deletions resources/scripts/api/server/getServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export interface Server {
internalId: number | string;
uuid: string;
name: string;
node: string;
node: {
name: string;
maintenanceMode: boolean;
};
status: ServerStatus;
sftpDetails: {
ip: string;
Expand Down Expand Up @@ -49,7 +52,10 @@ export const rawDataToServerObject = ({ attributes: data }: FractalResponseData)
internalId: data.internal_id,
uuid: data.uuid,
name: data.name,
node: data.node,
node: {
name: data.node.name,
maintenanceMode: data.node.maintenance_mode,
},
status: data.status,
invocation: data.invocation,
dockerImage: data.docker_image,
Expand Down
7 changes: 7 additions & 0 deletions resources/scripts/components/server/ConflictStateRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 isMaintenanceMode = ServerContext.useStoreState((state) => state.server.data?.node.maintenanceMode || false);

return status === 'installing' || status === 'install_failed' ? (
<ScreenBlock
Expand All @@ -21,6 +22,12 @@ export default () => {
image={ServerErrorSvg}
message={'This server is suspended and cannot be accessed.'}
/>
) : isMaintenanceMode ? (
<ScreenBlock
title={'Node under Maintenance'}
image={ServerErrorSvg}
message={'The node of this server is currently under maintenance.'}
/>
) : (
<ScreenBlock
title={isTransferring ? 'Transferring' : 'Restoring from Backup'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ const ServerConsoleContainer = () => {
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 isMaintenanceMode = ServerContext.useStoreState((state) => state.server.data!.node.maintenanceMode);

return (
<ServerContentBlock title={'Console'}>
{(isInstalling || isTransferring) && (
{(isMaintenanceMode || isInstalling || isTransferring) && (
<Alert type={'warning'} className={'mb-4'}>
{isInstalling
{isMaintenanceMode
? '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.'}
</Alert>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default () => {
<TitledGreyBox title={'Debug Information'} css={tw`mb-6 md:mb-10`}>
<div css={tw`flex items-center justify-between text-sm`}>
<p>Node</p>
<code css={tw`font-mono bg-neutral-900 rounded py-1 px-2`}>{node}</code>
<code css={tw`font-mono bg-neutral-900 rounded py-1 px-2`}>{node.name}</code>
</div>
<CopyOnClick text={uuid}>
<div css={tw`flex items-center justify-between mt-2 text-sm`}>
Expand Down
2 changes: 1 addition & 1 deletion resources/scripts/state/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.node.maintenanceMode;
}),

isInstalling: computed((state) => {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/nodes/view/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<div class="row">
@if($node->maintenance_mode)
<div class="col-sm-12">
<div class="info-box bg-grey">
<div class="info-box bg-orange">
<span class="info-box-icon"><i class="ion ion-wrench"></i></span>
<div class="info-box-content" style="padding: 23px 10px 0;">
<span class="info-box-text">This node is under</span>
Expand Down