From 66a0e049eed8c69d9486969f16ca2e5fcd0a4f65 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Thu, 9 Jul 2020 16:11:10 +0200 Subject: [PATCH] Fix resotring related flags in config response --- .../bubble/server/BubbleConfiguration.java | 31 +++++++++++++++---- .../bubble/service/backup/RestoreService.java | 6 ++-- bubble-web | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java b/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java index 4f1bfca8..9e530ac7 100644 --- a/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java +++ b/bubble-server/src/main/java/bubble/server/BubbleConfiguration.java @@ -51,6 +51,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import javax.annotation.Nullable; import java.beans.Transient; import java.io.File; import java.util.*; @@ -93,6 +94,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 = "restoringInProgress"; public static final String DEFAULT_LOCAL_STORAGE_DIR = HOME_DIR + "/.bubble_local_storage"; @@ -291,13 +293,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)}, @@ -312,19 +315,35 @@ 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()} })); + } 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(); } } + /** + * Return true if it is expected from the user to fillin data required for starting backup restoring process on + * this node of this network. + */ + private boolean isRestoringInProgress(@Nullable final BubbleNetwork thisNetwork) { + if (thisNetwork == null || thisNetwork.getState() != BubbleNetworkState.restoring) return false; + + // if restore process is already started, do not show the form to user again: + return !getBean(RestoreService.class).isSelfRestoreStarted(); + } + // called after activation, because now thisNetwork will be defined public void refreshPublicSystemConfigs () { synchronized (publicSystemConfigs) { publicSystemConfigs.set(null); } 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) { diff --git a/bubble-web b/bubble-web index ca8c4a1c..38af7d4e 160000 --- a/bubble-web +++ b/bubble-web @@ -1 +1 @@ -Subproject commit ca8c4a1c890ab70f0667d5ca1c0e8ac6fe796fbc +Subproject commit 38af7d4ed0f733e35f8a743a65331984c377d758