From b7b5d8e4142015073fea49e70322efcdcbc7b58f Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Mon, 18 Feb 2019 23:47:45 -0800 Subject: [PATCH] Placeholder for phase 1 and 2 --- src/user/system/BackupManager.ts | 16 ++++++++++++++++ src/user/system/CaptainManager.ts | 3 +++ src/utils/CaptainInstaller.ts | 7 ++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/user/system/BackupManager.ts b/src/user/system/BackupManager.ts index d46191e..6db46fd 100644 --- a/src/user/system/BackupManager.ts +++ b/src/user/system/BackupManager.ts @@ -62,6 +62,22 @@ export default class BackupManager { return !!this.longOperationInProgress } + startRestorationIfNeededPhase1() { + // if (/captain/restore/restore-instructions.json does exist): + // - Connect all extra nodes via SSH and get their NodeID + // - Replace the nodeId in apps with the new nodeId based on restore-instructions.json + // - Create a captain-salt secret using the data in restore + // - Copy restore files to proper places + } + + startRestorationIfNeededPhase2() { + // if (/captain/restore/restore.json exists) GO TO RESTORE MODE: + // - Double check salt against "meta/captain-salt" + // - Iterate over all APPs and make sure they are inited properly + // - Delete /captain/restore + // - Wait until things settle (1 minute...) + } + checkAndPrepareRestoration() { const self = this return Promise.resolve() // diff --git a/src/user/system/CaptainManager.ts b/src/user/system/CaptainManager.ts index cc1a9be..7af346c 100644 --- a/src/user/system/CaptainManager.ts +++ b/src/user/system/CaptainManager.ts @@ -233,6 +233,9 @@ class CaptainManager { return Promise.resolve(true) }) + .then(function() { + return self.backupManager.startRestorationIfNeededPhase2() + }) .then(function() { self.inited = true diff --git a/src/utils/CaptainInstaller.ts b/src/utils/CaptainInstaller.ts index 1b31178..0753bb5 100644 --- a/src/utils/CaptainInstaller.ts +++ b/src/utils/CaptainInstaller.ts @@ -195,6 +195,8 @@ function printTroubleShootingUrl() { let myIp4: string export function install() { + const backupManger = new BackupManager() + Promise.resolve() .then(function() { printTroubleShootingUrl() @@ -250,13 +252,16 @@ export function install() { return checkPortOrThrow(myIp4, 3000) }) .then(function() { - return new BackupManager().checkAndPrepareRestoration() + return backupManger.checkAndPrepareRestoration() }) .then(function() { return DockerApi.get().initSwarm(myIp4) }) .then(function(swarmId: string) { console.log('Swarm started: ' + swarmId) + return backupManger.startRestorationIfNeededPhase1() + }) + .then(function() { return DockerApi.get().getLeaderNodeId() }) .then(function(nodeId: string) {