Skip to content

Commit

Permalink
Updates to backup/restore
Browse files Browse the repository at this point in the history
  • Loading branch information
tagyoureit committed Nov 24, 2021
1 parent 5b83069 commit c9cc00a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
2 changes: 2 additions & 0 deletions controller/boards/EasyTouchBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,7 @@ export class TouchCircuitCommands extends CircuitCommands {
// response: [255,0,255][165,33,34,16,1,1][139][1,133]
let id = parseInt(data.id, 10);
if (isNaN(id)) return Promise.reject(new InvalidEquipmentIdError('Circuit Id is invalid', data.id, 'Feature'));
if (id >= 255 || data.master === 1) return super.setCircuitAsync(data);
let circuit = sys.circuits.getInterfaceById(id);
// Alright check to see if we are adding a nixie circuit.
if (id === -1 || circuit.master !== 0) {
Expand Down Expand Up @@ -1302,6 +1303,7 @@ export class TouchCircuitCommands extends CircuitCommands {
circuit.eggTimer = typeof data.eggTimer !== 'undefined' ? parseInt(data.eggTimer, 10) : circuit.eggTimer || 720;
circuit.dontStop = (typeof data.dontStop !== 'undefined') ? utils.makeBool(data.dontStop) : circuit.eggTimer === 1620;
cstate.isActive = circuit.isActive = true;
circuit.master = 0;
let eggTimer = sys.eggTimers.find(elem => elem.circuit === parseInt(data.id, 10));
try {
if (circuit.eggTimer === 720) {
Expand Down
1 change: 1 addition & 0 deletions controller/boards/IntelliCenterBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ class IntelliCenterCircuitCommands extends CircuitCommands {
scircuit.name = circuit.name = typeof data.name !== 'undefined' ? data.name.toString().substring(0, 16) : circuit.name;
scircuit.type = circuit.type = type;
scircuit.isActive = circuit.isActive = true;
circuit.master = 0;
resolve(circuit);
}
}
Expand Down
6 changes: 5 additions & 1 deletion controller/boards/SystemBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3803,7 +3803,11 @@ export class ChemControllerCommands extends BoardCommands {
try {
// pull a little trick to first add the data then perform the update. This way we won't get a new id or
// it won't error out.
sys.chemControllers.getItemById(c, true);
let chem = sys.chemControllers.getItemById(c.id, true);
// RSG 11.24.21. setChemControllerAsync will only set the type/address if it thinks it's new.
// For a restore, if we set the type/address here it will pass the validation steps.
chem.type = c.type;
// chem.address = c.address;
await sys.board.chemControllers.setChemControllerAsync(c);
res.addModuleSuccess('chemController', `Add: ${c.id}-${c.name}`);
} catch (err) { res.addModuleError('chemController', `Add: ${c.id}-${c.name}: ${err.message}`); }
Expand Down
1 change: 1 addition & 0 deletions controller/comms/messages/config/ChlorinatorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class ChlorinatorMessage {
}
if (typeof chlor.name === 'undefined') schlor.name = chlor.name = msg.extractPayloadString(6, 16);
if (typeof chlor.model === 'undefined') chlor.model = sys.board.valueMaps.chlorinatorModel.getValue(schlor.name.toLowerCase());
if (typeof chlor.type === 'undefined') chlor.type = schlor.type = 0;
schlor.saltLevel = msg.extractPayloadByte(3) * 50 || schlor.saltLevel;
schlor.status = msg.extractPayloadByte(4) & 0x007F; // Strip off the high bit. The chlorinator does not actually report this.;
// Pull the hours from the 25 message.
Expand Down
2 changes: 1 addition & 1 deletion controller/nixie/chemistry/ChemController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class NixieChemControllerCollection extends NixieEquipmentCollection<Nixi
ncc = NixieChemControllerBase.create(this.controlPanel, chem);
this.push(ncc);
let ctype = sys.board.valueMaps.chemControllerTypes.transform(chem.type);
logger.info(`A Chem controller was not found for id #${chem.id} starting ${ctype.desc}`);
logger.info(`Nixie Chem Controller was created at id #${chem.id} for type ${ctype.desc}`);
await ncc.setControllerAsync(data);
}
else {
Expand Down
40 changes: 36 additions & 4 deletions web/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export class WebServer {
}
public async backupServer(opts: any): Promise<BackupFile> {
let ret = new BackupFile();
ret.options = extend(true, {}, opts, { version: 1.0, errors: [] });
ret.options = extend(true, {}, opts, { version: 1.1, errors: [] });
//{ file: '', options: extend(true, {}, opts, { version: 1.0, errors: [] }) };
let jszip = require("jszip");
function pad(n) { return (n < 10 ? '0' : '') + n; }
Expand Down Expand Up @@ -396,14 +396,27 @@ export class WebServer {
for (let i = 0; i < opts.options.servers.length; i++) {
let s = opts.options.servers[i];
if (s.restore) {
// Check to see if the server is on-line.
let ctx: any = { server: { uuid: s.uuid, name: s.name, errors: [], warnings: [] } };
// Check to see if the server is on-line.
// First, try by UUID.
let srv = this.findServerByGuid(s.uuid) as REMInterfaceServer;
let cfg = rest.servers.find(elem => elem.uuid === s.uuid);
let ctx: any = { server: { uuid: s.uuid, name: s.name, errors: [], warnings: [] } };
// Second, try by host
if (typeof srv === 'undefined' && parseFloat(opts.options.version) >= 1.1) {
let srvs = this.findServersByType('rem') as REMInterfaceServer[];
cfg = rest.servers.find(elem => elem.serverConfig.options.host === s.host);
for (let j = 0; j < srvs.length; j++){
if (srvs[j].cfg.options.host === cfg.serverConfig.options.host){
srv = srvs[j];
ctx.server.warnings.push(`REM Server from backup file (${srv.uuid}/${srv.cfg.options.host}) matched to current REM Server (${cfg.uuid}/${cfg.serverConfig.options.host}) by host name or IP and not UUID. UUID in current config.json for REM will be updated.`)
break;
}
}
}
stats.servers.push(ctx);
if (typeof cfg === 'undefined' || typeof cfg.controllerConfig === 'undefined') ctx.server.errors.push(`Server configuration not found in zip file`);
else if (typeof srv === 'undefined') ctx.server.errors.push(`Server ${s.name} is not enabled in njsPC cannot restore.`);
else if (!srv.isConnected) ctx.server.errors.push(`Server ${s.name} is not connected cannot restore.`);
else if (!srv.isConnected) ctx.server.errors.push(`Server ${s.name} is not connected or cannot be found by UUID and cannot restore. If this is a version 1.0 file, update your current REM UUID to match the backup REM UUID.`);
else {
let resp = await srv.validateRestore(cfg.controllerConfig);
if (typeof resp !== 'undefined') {
Expand Down Expand Up @@ -448,7 +461,26 @@ export class WebServer {
let srv = this.findServerByGuid(s.uuid) as REMInterfaceServer;
let cfg = rest.servers.find(elem => elem.uuid === s.uuid);
let ctx: any = { server: { uuid: s.uuid, name: s.name, errors: [], warnings: [] } };
if (typeof srv === 'undefined' && parseFloat(opts.options.version) >= 1.1) {
let srvs = this.findServersByType('rem') as REMInterfaceServer[];
cfg = rest.servers.find(elem => elem.serverConfig.options.host === s.host);
for (let j = 0; j < srvs.length; j++){
if (srvs[j].cfg.options.host === cfg.serverConfig.options.host){
srv = srvs[j];
let oldSrvCfg = srv.cfg;
oldSrvCfg.enabled = false;
await this.updateServerInterface(oldSrvCfg); // unload prev server interface
srv.uuid = srv.cfg.uuid = cfg.uuid;
config.setSection('web.interfaces.rem', cfg.serverConfig);
await this.updateServerInterface(cfg.serverConfig); // reset server interface
srv = this.findServerByGuid(s.uuid) as REMInterfaceServer;
logger.info(`Restore REM: Current UUID updated to UUID of backup.`);
break;
}
}
}
stats.servers.push(ctx);
if (!srv.isConnected) await utils.sleep(6000); // rem server waits to connect 5s before isConnected will be true. Server.ts#1256 = REMInterfaceServer.init(); What's a better way to do this?
if (typeof cfg === 'undefined' || typeof cfg.controllerConfig === 'undefined') ctx.server.errors.push(`Server configuration not found in zip file`);
else if (typeof srv === 'undefined') ctx.server.errors.push(`Server ${s.name} is not enabled in njsPC cannot restore.`);
else if (!srv.isConnected) ctx.server.errors.push(`Server ${s.name} is not connected cannot restore.`);
Expand Down
2 changes: 1 addition & 1 deletion web/services/config/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ export class ConfigRoute {
// Just in case somebody deletes the backup section and doesn't put it back properly.
for (let i = 0; i < servers.length; i++) {
let srv = servers[i];
if (typeof opts.servers.find(elem => elem.uuid === srv.uuid) === 'undefined') opts.servers.push({ name: srv.name, uuid: srv.uuid, backup: false });
if (typeof opts.servers.find(elem => elem.uuid === srv.uuid) === 'undefined') opts.servers.push({ name: srv.name, uuid: srv.uuid, backup: false, host: srv.interface.options.host });
}
for (let i = opts.servers.length - 1; i >= 0; i--) {
let srv = opts.servers[i];
Expand Down

0 comments on commit c9cc00a

Please sign in to comment.