Browse Source

Fix resotring related flags in config response

pull/26/head
Kristijan Mitrovic 4 years ago
parent
commit
66a0e049ee
3 changed files with 29 additions and 10 deletions
  1. +25
    -6
      bubble-server/src/main/java/bubble/server/BubbleConfiguration.java
  2. +3
    -3
      bubble-server/src/main/java/bubble/service/backup/RestoreService.java
  3. +1
    -1
      bubble-web

+ 25
- 6
bubble-server/src/main/java/bubble/server/BubbleConfiguration.java View File

@@ -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<Map<String, Object>> publicSystemConfigs = new AtomicReference<>();
public Map<String, Object> 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); }


+ 3
- 3
bubble-server/src/main/java/bubble/service/backup/RestoreService.java View File

@@ -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) {


+ 1
- 1
bubble-web

@@ -1 +1 @@
Subproject commit ca8c4a1c890ab70f0667d5ca1c0e8ac6fe796fbc
Subproject commit 38af7d4ed0f733e35f8a743a65331984c377d758

Loading…
Cancel
Save