From 96a4a5f05583d8c3e7bd8ee06221bcf80e657906 Mon Sep 17 00:00:00 2001 From: James Chapman Date: Thu, 29 Aug 2024 09:34:03 +0000 Subject: [PATCH] rework --- src/cockpit/389-console/src/database.jsx | 4 +- .../src/lib/database/databaseConfig.jsx | 156 +++++++++--------- 2 files changed, 83 insertions(+), 77 deletions(-) diff --git a/src/cockpit/389-console/src/database.jsx b/src/cockpit/389-console/src/database.jsx index 1030e5b193..fce4cd5dd4 100644 --- a/src/cockpit/389-console/src/database.jsx +++ b/src/cockpit/389-console/src/database.jsx @@ -85,12 +85,12 @@ export class Database extends React.Component { globalDBConfig: { activeTab: 0, }, + backendImplement: BE_IMPL_MDB, configUpdated: 0, // Chaining Config chainingConfig: {}, chainingUpdated: 0, chainingActiveKey: 0, - backendImplement: "mdb", // Chaining Link chainingLoading: false, // Suffix @@ -250,7 +250,6 @@ export class Database extends React.Component { dbimplement = attrs['nsslapd-backend-implement'][0]; this.setState({ backendImplement: dbimplement }); } - if (dbimplement === BE_IMPL_BDB) { let db_cache_auto = false; let import_cache_auto = false; @@ -319,7 +318,6 @@ export class Database extends React.Component { mdbmaxreaders: attrs['nsslapd-mdb-max-readers'][0], mdbmaxdbs: attrs['nsslapd-mdb-max-dbs'][0], dbhomedir: dbhome, - importcachesize: attrs['nsslapd-import-cachesize'][0], }, configUpdated: 1 }), () => { this.loadNDN() }); diff --git a/src/cockpit/389-console/src/lib/database/databaseConfig.jsx b/src/cockpit/389-console/src/lib/database/databaseConfig.jsx index 933d723f4f..ef24c19627 100644 --- a/src/cockpit/389-console/src/lib/database/databaseConfig.jsx +++ b/src/cockpit/389-console/src/lib/database/databaseConfig.jsx @@ -992,11 +992,13 @@ GlobalDatabaseConfig.defaultProps = { }; export class GlobalDatabaseConfigMDB extends React.Component { + ismounted = false; constructor(props) { super(props); this.state = { saving: false, saveBtnDisabled: true, + availDbSizeBytes: 0, activeTabKey: this.props.data.activeTab, db_cache_auto: this.props.data.db_cache_auto, import_cache_auto: this.props.data.import_cache_auto, @@ -1009,7 +1011,6 @@ export class GlobalDatabaseConfigMDB extends React.Component { mdbmaxsize: this.props.data.mdbmaxsize, mdbmaxreaders: this.props.data.mdbmaxreaders, mdbmaxdbs: this.props.data.mdbmaxdbs, - importcachesize: this.props.data.importcachesize, ndncachemaxsize: this.props.data.ndncachemaxsize, // These variables store the original value (used for saving config) _looklimit: this.props.data.looklimit, @@ -1021,20 +1022,25 @@ export class GlobalDatabaseConfigMDB extends React.Component { _mdbmaxsize: this.props.data.mdbmaxsize, _mdbmaxreaders: this.props.data.mdbmaxreaders, _mdbmaxdbs: this.props.data.mdbmaxdbs, - _importcachesize: this.props.data.importcachesize, _ndncachemaxsize: this.props.data.ndncachemaxsize, }; this.validateSaveBtn = this.validateSaveBtn.bind(this); this.handleChange = this.handleChange.bind(this); - this.handleTimeChange = this.handleTimeChange.bind(this); this.handleSaveDBConfig = this.handleSaveDBConfig.bind(this); + this.loadAvailableDiskSpace = this.loadAvailableDiskSpace.bind(this); this.maxValue = 2147483647; this.onMinusConfig = (id) => { - this.setState({ - [id]: Number(this.state[id]) - 1 - }, () => { this.validateSaveBtn() }); + if (id === "mdbmaxsize") { + this.setState({ + [id]: Number(this.state[id]) - (1024 * 1024) + }, () => { this.validateSaveBtn() }); + } else { + this.setState({ + [id]: Number(this.state[id]) - 1 + }, () => { this.validateSaveBtn() }); + } }; this.onConfigChange = (event, id, min, max) => { let maxValue = this.maxValue; @@ -1042,14 +1048,27 @@ export class GlobalDatabaseConfigMDB extends React.Component { maxValue = max; } const newValue = isNaN(event.target.value) ? 0 : Number(event.target.value); - this.setState({ - [id]: newValue > maxValue ? maxValue : newValue < min ? min : newValue - }, () => { this.validateSaveBtn() }); + if (id === "mdbmaxsize") { + const newValueBytes = newValue * (1024 * 1024); + this.setState({ + [id]: (newValueBytes > max ? max : newValueBytes < min ? min : newValueBytes) + }, () => { this.validateSaveBtn() }); + } else { + this.setState({ + [id]: newValue > maxValue ? maxValue : newValue < min ? min : newValue + }, () => { this.validateSaveBtn() }); + } }; this.onPlusConfig = (id) => { - this.setState({ - [id]: Number(this.state[id]) + 1 - }, () => { this.validateSaveBtn() }); + if (id === "mdbmaxsize") { + this.setState({ + [id]: Number(this.state[id]) + (1024 * 1024) + }, () => { this.validateSaveBtn() }); + } else { + this.setState({ + [id]: Number(this.state[id]) + 1 + }, () => { this.validateSaveBtn() }); + } }; // Toggle currently active tab @@ -1061,26 +1080,34 @@ export class GlobalDatabaseConfigMDB extends React.Component { } componentDidMount() { + this.ismounted = true; this.props.enableTree(); + this.loadAvailableDiskSpace(); + } + + componentWillUnmount() { + this.ismounted = false; } validateSaveBtn() { let saveBtnDisabled = true; const check_attrs = [ - "looklimit", "idscanlimit", "pagelooklimit", "pagescanlimit", - "rangelooklimit", "importcachesize", "ndncachemaxsize", + "looklimit", "idscanlimit", "pagelooklimit", + "pagescanlimit", "rangelooklimit", "ndncachemaxsize", "mdbmaxsize", "mdbmaxreaders", "mdbmaxdbs", ]; // Check if a setting was changed, if so enable the save button for (const config_attr of check_attrs) { if (this.state[config_attr] !== this.state['_' + config_attr]) { + // jc console.log(config_attr); saveBtnDisabled = false; break; } } + // jc console.log(saveBtnDisabled); this.setState({ - saveBtnDisabled, + saveBtnDisabled }); } @@ -1094,12 +1121,6 @@ export class GlobalDatabaseConfigMDB extends React.Component { }, () => { this.validateSaveBtn() }); } - handleTimeChange(value) { - this.setState({ - compacttime: value, - }, () => { this.validateSaveBtn() }); - } - save_ndn_cache(requireRestart) { const msg = "Successfully updated database configuration"; if (this.state._ndncachemaxsize !== this.state.ndncachemaxsize) { @@ -1193,13 +1214,6 @@ export class GlobalDatabaseConfigMDB extends React.Component { cmd.push("--mdb-max-dbs=" + this.state.mdbmaxdbs); requireRestart = true; } - if (this.state._dbhomedir !== this.state.dbhomedir) { - cmd.push("--db-home-directory=" + this.state.dbhomedir); - requireRestart = true; - } - if (this.state._importcachesize !== this.state.importcachesize) { - cmd.push("--import-cachesize=" + this.state.importcachesize); - } if (cmd.length > 6) { this.setState({ saving: true @@ -1229,6 +1243,27 @@ export class GlobalDatabaseConfigMDB extends React.Component { } } + loadAvailableDiskSpace() { + let available = 0; + const cmd = "df -B1 " + this.state.dbhomedir + " | awk '{print $4}'"; + // log_cmd("loadAvailableDiskSpace", "Load available disk space", cmd); + cockpit + .script(cmd, [], { superuser: true, err: "message" }) + .done(output => { + available = output.split(/\s+/)[1]; + if (this.ismounted) { + this.setState({ + availDbSizeBytes: available, + }); + } + }) + .fail(() => { + this.setState({ + availDbSizeBytes: available, + }); + }); + } + render() { let spinner = ""; if (this.state.loading) { @@ -1267,23 +1302,24 @@ export class GlobalDatabaseConfigMDB extends React.Component {
{_("Database Maximum Size")} { this.onMinusConfig("mdbmaxsize") }} - onChange={(e) => { this.onConfigChange(e, "mdbmaxsize", 1, 0) }} + onChange={(e) => { this.onConfigChange(e, "mdbmaxsize", 104857600, this.state.availDbSizeBytes) }} onPlus={() => { this.onPlusConfig("mdbmaxsize") }} inputName="input" inputAriaLabel="number input" minusBtnAriaLabel="minus" plusBtnAriaLabel="plus" + unit="MB" widthChars={10} /> @@ -1317,7 +1353,7 @@ export class GlobalDatabaseConfigMDB extends React.Component { {_("ID List Scan Limit")} @@ -1340,7 +1376,7 @@ export class GlobalDatabaseConfigMDB extends React.Component { {_("Paged Search Look Through Limit")} @@ -1363,7 +1399,7 @@ export class GlobalDatabaseConfigMDB extends React.Component { {_("Paged Search ID List Scan Limit")} @@ -1386,7 +1422,7 @@ export class GlobalDatabaseConfigMDB extends React.Component { {_("Range Search Look Through Limit")} @@ -1410,34 +1446,6 @@ export class GlobalDatabaseConfigMDB extends React.Component {
- {_("Import Cache")}}> -
- - - {_("Import Cache Size")} - - - { this.onMinusConfig("importcachesize") }} - onChange={(e) => { this.onConfigChange(e, "importcachesize", 512000, 0) }} - onPlus={() => { this.onPlusConfig("importcachesize") }} - inputName="input" - inputAriaLabel="number input" - minusBtnAriaLabel="minus" - plusBtnAriaLabel="plus" - widthChars={10} - /> - - -
-
- {_("NDN Cache")}}>
{_("Advanced Settings")}}>
{_("Database Home Directory")} @@ -1479,16 +1487,16 @@ export class GlobalDatabaseConfigMDB extends React.Component { {_("Database Max Readers")} @@ -1499,7 +1507,7 @@ export class GlobalDatabaseConfigMDB extends React.Component { min={0} max={200} onMinus={() => { this.onMinusConfig("mdbmaxreaders") }} - onChange={(e) => { this.onConfigChange(e, "mdbmaxreaders", 1, 0) }} + onChange={(e) => { this.onConfigChange(e, "mdbmaxreaders", 0, 200) }} onPlus={() => { this.onPlusConfig("mdbmaxreaders") }} inputName="input" inputAriaLabel="number input" @@ -1511,10 +1519,10 @@ export class GlobalDatabaseConfigMDB extends React.Component { - {_("Database Max DBS")} + {_("Database Max DBs")} { this.onMinusConfig("mdbmaxdbs") }} - onChange={(e) => { this.onConfigChange(e, "mdbmaxdbs", 10, 0) }} + onChange={(e) => { this.onConfigChange(e, "mdbmaxdbs", 36, 5000) }} onPlus={() => { this.onPlusConfig("mdbmaxdbs") }} inputName="input" inputAriaLabel="number input"