diff --git a/packages/controller/src/Controller.ts b/packages/controller/src/Controller.ts index 18a38751..9c6b2f6c 100644 --- a/packages/controller/src/Controller.ts +++ b/packages/controller/src/Controller.ts @@ -523,7 +523,7 @@ export default class Controller { } requests.push(hostConnection.send(new lib.SystemInfoRequest())); } - requests.push(lib.gatherSystemInfo("controller", this.canRestart)); + requests.push(lib.gatherSystemInfo("controller", this.canRestart, this.config.restartRequired)); const newMetrics = await Promise.all(requests); for (const metric of newMetrics) { this.systems.set(metric); diff --git a/packages/host/src/Host.ts b/packages/host/src/Host.ts index 0e60d2a1..2b11e696 100644 --- a/packages/host/src/Host.ts +++ b/packages/host/src/Host.ts @@ -798,7 +798,7 @@ export default class Host extends lib.Link { } async handleSystemInfoRequest() { - return lib.gatherSystemInfo(this.config.get("host.id"), this.canRestart); + return lib.gatherSystemInfo(this.config.get("host.id"), this.canRestart, this.config.restartRequired); } async handleHostMetricsRequest() { diff --git a/packages/lib/src/config/classes.ts b/packages/lib/src/config/classes.ts index 2546dbf8..310312ba 100644 --- a/packages/lib/src/config/classes.ts +++ b/packages/lib/src/config/classes.ts @@ -203,6 +203,8 @@ export class Config< /** Set to true when a field in the config is changed. */ dirty = false; + /** Set to true when a 'restart required' field in the config is changed. */ + restartRequired = false; /** * Create a new instance of the given config @@ -272,6 +274,27 @@ export class Config< return true; } + /** + * Set the value of a field, while also settings the required flags and events. + * This method does not perform any validation on the value being set + * + * @param name - Name of the field to set + * @param value - The new value of the field + * @param notify - False to skip setting dirty flags and emitting events + */ + _set(name: keyof Fields & string, value: FieldValue, notify: boolean = true) { + const prev = this.fields[name]; + this.fields[name] = value as any; + if (notify && !isDeepStrictEqual(value, prev)) { + const def = this.constructor.fieldDefinitions[name]; + if (def.restartRequired) { + this.restartRequired = true; + } + this.dirty = true; + this.emit("fieldChanged", name, value, prev); + } + } + static jsonSchema = ConfigSchema; static validate = libSchema.compile(this.jsonSchema as any); @@ -391,12 +414,7 @@ export class Config< continue; } - let prev = this.fields[name]; - this.fields[name] = value as any; - if (notify && !isDeepStrictEqual(value, prev)) { - this.dirty = true; - this.emit("fieldChanged", name, value, prev); - } + this._set(name, value, notify); } } @@ -511,12 +529,7 @@ export class Config< throw new InvalidValue(`Expected type of ${name} to be ${def.type}, not ${basicType(value)}`); } - let prev = this.fields[name]; - this.fields[name] = value as Fields[Field]; - if (!isDeepStrictEqual(value, prev)) { - this.dirty = true; - this.emit("fieldChanged", name, value, prev); - } + this._set(name, value); } /** @@ -559,10 +572,7 @@ export class Config< } else { delete updated[prop]; } - this.fields[name] = updated as Fields[Field]; - if (!isDeepStrictEqual(updated, prev)) { - this.dirty = true; - this.emit("fieldChanged", name, updated, prev); - } + + this._set(name, updated); } } diff --git a/packages/lib/src/data/messages_controller.ts b/packages/lib/src/data/messages_controller.ts index cd51704a..dd2c858f 100644 --- a/packages/lib/src/data/messages_controller.ts +++ b/packages/lib/src/data/messages_controller.ts @@ -250,6 +250,7 @@ export class SystemInfo { public diskCapacity: number, public diskAvailable: number, public canRestart: boolean, + public restartRequired: boolean, /** Millisecond Unix timestamp this entry was last updated at */ public updatedAtMs: number, public isDeleted: boolean, @@ -268,6 +269,7 @@ export class SystemInfo { "diskCapacity": Type.Number(), "diskAvailable": Type.Number(), "canRestart": Type.Boolean(), + "restartRequired": Type.Boolean(), "updatedAtMs": Type.Number(), "isDeleted": Type.Boolean(), }); @@ -286,6 +288,7 @@ export class SystemInfo { json.diskCapacity, json.diskAvailable, json.canRestart, + json.restartRequired, json.updatedAtMs, json.isDeleted, ); diff --git a/packages/lib/src/system_collectors.ts b/packages/lib/src/system_collectors.ts index fa689c97..6822e474 100644 --- a/packages/lib/src/system_collectors.ts +++ b/packages/lib/src/system_collectors.ts @@ -134,7 +134,7 @@ function minZip(a: T[], b: T[]): [T, T][] { let previousTotalCpuMs: number[] = []; let previousIdleCpuMs: number[] = []; -export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean) { +export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean, restartRequired: boolean) { const cpus = os.cpus(); const currentTotalCpuMs = cpus.map(({ times }) => times.user + times.idle + times.irq + times.nice + times.sys); const currentIdleCpuMs = cpus.map(({ times }) => times.idle); @@ -165,6 +165,7 @@ export async function gatherSystemInfo(id: SystemInfo["id"], canRestart: boolean diskCapacity, diskAvailable, canRestart, + restartRequired, Date.now(), false, ); diff --git a/packages/web_ui/src/components/ControllerPage.tsx b/packages/web_ui/src/components/ControllerPage.tsx index 135b9e81..05f9152e 100644 --- a/packages/web_ui/src/components/ControllerPage.tsx +++ b/packages/web_ui/src/components/ControllerPage.tsx @@ -1,5 +1,6 @@ import React, {useContext, useState} from "react"; -import { Button, Descriptions, Flex, Popconfirm, Space, Typography } from "antd"; +import { Button, Descriptions, Flex, Popconfirm, Space, Tooltip, Typography } from "antd"; +import { ExclamationCircleOutlined } from "@ant-design/icons"; import * as lib from "@clusterio/lib"; @@ -54,16 +55,20 @@ export default function ControllerPage() { } { account.hasPermission("core.controller.restart") - && + && + + } } /> diff --git a/packages/web_ui/src/components/HostViewPage.tsx b/packages/web_ui/src/components/HostViewPage.tsx index 526a070e..8739fa67 100644 --- a/packages/web_ui/src/components/HostViewPage.tsx +++ b/packages/web_ui/src/components/HostViewPage.tsx @@ -1,5 +1,6 @@ import React, { useContext, useState } from "react"; -import { Descriptions, Spin, Tag, Typography, Button, Space, Modal, Popconfirm, Flex } from "antd"; +import { Descriptions, Spin, Tag, Typography, Button, Space, Modal, Popconfirm, Flex, Tooltip } from "antd"; +import { ExclamationCircleOutlined } from "@ant-design/icons"; import { useParams } from "react-router-dom"; import * as lib from "@clusterio/lib"; @@ -89,17 +90,21 @@ export default function HostViewPage() { } { account.hasPermission("core.host.restart") - && + && + + } ; diff --git a/packages/web_ui/src/components/HostsPage.tsx b/packages/web_ui/src/components/HostsPage.tsx index 015f1b2d..e6212271 100644 --- a/packages/web_ui/src/components/HostsPage.tsx +++ b/packages/web_ui/src/components/HostsPage.tsx @@ -1,10 +1,11 @@ import React, { useContext, useRef, useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; -import { Button, Flex, Form, InputNumber, Modal, Progress, Switch, Table, Tag, Typography } from "antd"; -import CopyOutlined from "@ant-design/icons/lib/icons/CopyOutlined"; +import { Button, Flex, Form, InputNumber, Modal, Progress, Space, Switch, Table, Tag, Tooltip, Typography } from "antd"; +import { ExclamationCircleOutlined, CopyOutlined } from "@ant-design/icons"; import * as lib from "@clusterio/lib"; +import webUiPackage from "../../package.json"; import { useAccount } from "../model/account"; import ControlContext from "./ControlContext"; import PageHeader from "./PageHeader"; @@ -13,6 +14,7 @@ import PluginExtra from "./PluginExtra"; import { MetricCpuRatio, MetricCpuUsed, MetricMemoryRatio, MetricMemoryUsed, MetricDiskUsed, MetricDiskRatio, + RestartRequired, } from "./system_metrics"; import { useHosts } from "../model/host"; import { useSystems } from "../model/system"; @@ -268,6 +270,12 @@ export default function HostsPage() { { title: "Version", dataIndex: "version", + render: (_, host) => + {host.version} + {webUiPackage.version === host.version ? undefined : + + } + , sorter: (a, b) => strcmp(a.version, b.version), }, { @@ -278,11 +286,14 @@ export default function HostsPage() { { title: "Connected", key: "connected", - render: (_, host) => - {host.connected ? "Connected" : "Disconnected"} - , + render: (_, host) => <> + + {host.connected ? "Connected" : "Disconnected"} + + + , sorter: (a, b) => Number(a.connected) - Number(b.connected), }, ]} diff --git a/packages/web_ui/src/components/system_metrics.tsx b/packages/web_ui/src/components/system_metrics.tsx index 4a6b3b03..34e503da 100644 --- a/packages/web_ui/src/components/system_metrics.tsx +++ b/packages/web_ui/src/components/system_metrics.tsx @@ -1,7 +1,8 @@ import React from "react"; import * as lib from "@clusterio/lib"; -import { Progress } from "antd"; +import { Progress, Tooltip } from "antd"; +import { ReloadOutlined } from "@ant-design/icons"; export function MetricCpuRatio(props: { system?: lib.SystemInfo }) { if (!props.system) { @@ -53,3 +54,12 @@ export function MetricDiskUsed(props: { system?: lib.SystemInfo }) { const capacity = lib.formatBytes(props.system.diskCapacity); return `${used} / ${capacity}`; } + +export function RestartRequired(props: { system?: lib.SystemInfo }) { + if (!props.system || !props.system.restartRequired) { + return ""; + } + return + + ; +} diff --git a/test/lib/data/SystemInfo.js b/test/lib/data/SystemInfo.js index 7b772e3d..7ee0b74f 100644 --- a/test/lib/data/SystemInfo.js +++ b/test/lib/data/SystemInfo.js @@ -21,6 +21,7 @@ describe("lib/data/SystemInfo", function() { 2048, 512, false, + false, 0, false );