From 2339b60ef28c209c652cedcd9035fba4fc239f94 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Fri, 10 Jul 2020 15:05:13 +0000 Subject: [PATCH] Fix restoring related flags in config response (#26) Merge branch 'master' of git.bubblev.org:bubblev/bubble into kris/fix_restore Rename restoreInProgress Merge branch 'master' into kris/fix_restore # Conflicts: # bubble-server/src/main/java/bubble/server/BubbleConfiguration.java # bubble-web Fix resotring related flags in config response Co-authored-by: Jonathan Cobb Co-authored-by: Kristijan Mitrovic Reviewed-on: https://git.bubblev.org/bubblev/bubble/pulls/26 --- .../bubble/server/BubbleConfiguration.java | 19 +++++++++++++------ .../bubble/service/backup/RestoreService.java | 6 +++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java b/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java index 6d1507f1..002f3f6b 100644 --- a/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java +++ b/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java @@ -91,6 +91,7 @@ public class BubbleConfiguration extends PgRestServerConfiguration public static final String TAG_SUPPORT = "support"; public static final String TAG_SECURITY_LEVELS = "securityLevels"; public static final String TAG_RESTORE_MODE = "awaitingRestore"; + public static final String TAG_RESTORING_IN_PROGRESS = "restoreInProgress"; public static final String TAG_JAR_VERSION = "jarVersion"; public static final String TAG_JAR_UPGRADE_AVAILABLE = "jarUpgradeAvailable"; @@ -309,13 +310,14 @@ public class BubbleConfiguration extends PgRestServerConfiguration private final AtomicReference> publicSystemConfigs = new AtomicReference<>(); public Map getPublicSystemConfigs () { + final var thisNetwork = getThisNetwork(); + final var awaitingRestore = thisNetwork != null && thisNetwork.getState() == BubbleNetworkState.restoring; + synchronized (publicSystemConfigs) { if (publicSystemConfigs.get() == null) { - final BubbleNetwork thisNetwork = getThisNetwork(); final AccountDAO accountDAO = getBean(AccountDAO.class); final CloudServiceDAO cloudDAO = getBean(CloudServiceDAO.class); final ActivationService activationService = getBean(ActivationService.class); - final RestoreService restoreService = getBean(RestoreService.class); publicSystemConfigs.set(MapBuilder.build(new Object[][]{ {TAG_ALLOW_REGISTRATION, thisNetwork == null ? null : thisNetwork.getBooleanTag(TAG_ALLOW_REGISTRATION, false)}, @@ -330,16 +332,21 @@ public class BubbleConfiguration extends PgRestServerConfiguration {TAG_CLOUD_CONFIGS, accountDAO.activated() ? null : activationService.getCloudDefaults()}, {TAG_LOCKED, accountDAO.locked()}, {TAG_LAUNCH_LOCK, isSageLauncher() || thisNetwork == null ? null : thisNetwork.launchLock()}, - {TAG_RESTORE_MODE, thisNetwork == null - ? false - : thisNetwork.getState() == BubbleNetworkState.restoring - && !restoreService.isRestoreStarted(thisNetwork.getUuid())}, + {TAG_RESTORE_MODE, awaitingRestore}, + {TAG_RESTORING_IN_PROGRESS, awaitingRestore + && getBean(RestoreService.class).isSelfRestoreStarted()}, {TAG_SSL_PORT, getDefaultSslPort()}, {TAG_SUPPORT, getSupport()}, {TAG_SECURITY_LEVELS, DeviceSecurityLevel.values()}, {TAG_JAR_VERSION, getVersion()}, {TAG_JAR_UPGRADE_AVAILABLE, getJarUpgradeAvailable() ? getSageVersionInfo() : null} })); + } else { + // some things has to be refreshed all the time in some cases: + if (awaitingRestore) { + publicSystemConfigs.get().put(TAG_RESTORING_IN_PROGRESS, + getBean(RestoreService.class).isSelfRestoreStarted()); + } } return publicSystemConfigs.get(); } diff --git a/bubble-server/src/main/java/bubble/service/backup/RestoreService.java b/bubble-server/src/main/java/bubble/service/backup/RestoreService.java index 687700d9..04fc42a7 100644 --- a/bubble-server/src/main/java/bubble/service/backup/RestoreService.java +++ b/bubble-server/src/main/java/bubble/service/backup/RestoreService.java @@ -35,7 +35,6 @@ import static org.cobbzilla.util.io.FileUtil.*; import static org.cobbzilla.util.json.JsonUtil.json; import static org.cobbzilla.util.security.CryptStream.BUFFER_SIZE; import static org.cobbzilla.wizard.cache.redis.RedisService.EX; -import static org.cobbzilla.wizard.cache.redis.RedisService.LOCK_SUFFIX; @Service @Slf4j public class RestoreService { @@ -66,8 +65,9 @@ public class RestoreService { public boolean isValidRestoreKey(String restoreKey) { return getRestoreKeys().exists(restoreKey); } - public boolean isRestoreStarted(String networkUuid) { - return getRestoreKeys().exists(networkUuid + LOCK_SUFFIX) || RESTORE_MARKER_FILE.exists(); + public boolean isSelfRestoreStarted() { + // only one restore may be started, hence + return getRestoreKeys().keys("*").size() > 0 || RESTORE_MARKER_FILE.exists(); } public boolean restore(String restoreKey, BubbleBackup backup) {