From 0ebddea55cbc8b46d41f2a477e4caf143bbe9704 Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Sun, 24 Feb 2019 22:07:26 -0800 Subject: [PATCH] Ensuring all NodeIDs for the backup are found in the restored swarm. --- src/user/system/BackupManager.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/user/system/BackupManager.ts b/src/user/system/BackupManager.ts index a2f73ce..6be8ca5 100644 --- a/src/user/system/BackupManager.ts +++ b/src/user/system/BackupManager.ts @@ -150,18 +150,28 @@ export default class BackupManager { appDefinitions: IHashMapGeneric } = fs.readJsonSync(configFilePathRestoring) - Object.keys(oldNodeIdToNewIpMap).forEach(oldNodeId => { - const newIp = oldNodeIdToNewIpMap[oldNodeId] - Object.keys(configData.appDefinitions).forEach(appName => { - if ( - configData.appDefinitions[appName].nodeId === - oldNodeId - ) { + Object.keys(configData.appDefinitions).forEach(appName => { + const oldNodeIdForApp = + configData.appDefinitions[appName].nodeId + + if (!oldNodeIdForApp) return + + let oldNodeIdFound = false + Object.keys(oldNodeIdToNewIpMap).forEach(oldNodeId => { + const newIp = oldNodeIdToNewIpMap[oldNodeId] + if (oldNodeIdForApp === oldNodeId) { + oldNodeIdFound = true configData.appDefinitions[appName].nodeId = newIp ? getNewNodeIdForIp(newIp) : '' // If user removed new IP, it will mean that the user is okay with this node being automatically assigned to a node ID } }) + + if (!oldNodeIdFound) { + throw new Error( + `Old nodeId ${oldNodeIdForApp} for app ${appName} is not found in the map.` + ) + } }) return fs.outputJson(configFilePathRestoring, configData)