@Test public void userFreezeRequestAppliedOnStartupWhenLocal() { underTest = new DatabaseFreezeServiceImpl(Collections.singleton(() -> databaseInstance), eventManager, databaseFrozenStateManager, () -> server, nodeAccess, securityHelper, ImmutableList.of()); when(nodeAccess.isClustered()).thenReturn(false); underTest.refreezeOnStartup(Arrays.asList(new FreezeRequest(InitiatorType.USER_INITIATED, INITIATOR_ID))); verify(databaseInstance).setFrozen(true); }
@VisibleForTesting void refreezeOnStartup(final List<FreezeRequest> state) { log.info("Restoring database frozen state on startup"); Map<InitiatorType, List<FreezeRequest>> requestsByInitiator = state.stream().collect(groupingBy(FreezeRequest::getInitiatorType)); for (FreezeRequest request : state) { log.warn("Database was frozen by {} process '{}' at {}", request.getInitiatorType(), request.getInitiatorId(), request.getTimestamp().withZone(DateTimeZone.getDefault())); } if (nodeAccess.isClustered()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } else { for (FreezeRequest request : requestsByInitiator.getOrDefault(SYSTEM, emptyList())) { log.warn("Discarding freeze request by {} process '{}'", request.getInitiatorType(), request.getInitiatorId()); databaseFrozenStateManager.remove(request); } if (!requestsByInitiator.getOrDefault(USER_INITIATED, emptyList()).isEmpty()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } } }
DatabaseFreezeServiceImpl extends StateGuardLifecycleSupport implements DatabaseFreezeService, EventAware, EventAware.Asynchronous { @VisibleForTesting void refreezeOnStartup(final List<FreezeRequest> state) { log.info("Restoring database frozen state on startup"); Map<InitiatorType, List<FreezeRequest>> requestsByInitiator = state.stream().collect(groupingBy(FreezeRequest::getInitiatorType)); for (FreezeRequest request : state) { log.warn("Database was frozen by {} process '{}' at {}", request.getInitiatorType(), request.getInitiatorId(), request.getTimestamp().withZone(DateTimeZone.getDefault())); } if (nodeAccess.isClustered()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } else { for (FreezeRequest request : requestsByInitiator.getOrDefault(SYSTEM, emptyList())) { log.warn("Discarding freeze request by {} process '{}'", request.getInitiatorType(), request.getInitiatorId()); databaseFrozenStateManager.remove(request); } if (!requestsByInitiator.getOrDefault(USER_INITIATED, emptyList()).isEmpty()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } } } }
DatabaseFreezeServiceImpl extends StateGuardLifecycleSupport implements DatabaseFreezeService, EventAware, EventAware.Asynchronous { @VisibleForTesting void refreezeOnStartup(final List<FreezeRequest> state) { log.info("Restoring database frozen state on startup"); Map<InitiatorType, List<FreezeRequest>> requestsByInitiator = state.stream().collect(groupingBy(FreezeRequest::getInitiatorType)); for (FreezeRequest request : state) { log.warn("Database was frozen by {} process '{}' at {}", request.getInitiatorType(), request.getInitiatorId(), request.getTimestamp().withZone(DateTimeZone.getDefault())); } if (nodeAccess.isClustered()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } else { for (FreezeRequest request : requestsByInitiator.getOrDefault(SYSTEM, emptyList())) { log.warn("Discarding freeze request by {} process '{}'", request.getInitiatorType(), request.getInitiatorId()); databaseFrozenStateManager.remove(request); } if (!requestsByInitiator.getOrDefault(USER_INITIATED, emptyList()).isEmpty()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } } } @Inject  DatabaseFreezeServiceImpl(final Set<Provider<DatabaseInstance>> providers,
                                   final EventManager eventManager,
                                   final DatabaseFrozenStateManager databaseFrozenStateManager,
                                   final Provider<OServer> server,
                                   final NodeAccess nodeAccess,
                                   final SecurityHelper securityHelper,
                                   final List<Freezable> freezables); }
DatabaseFreezeServiceImpl extends StateGuardLifecycleSupport implements DatabaseFreezeService, EventAware, EventAware.Asynchronous { @VisibleForTesting void refreezeOnStartup(final List<FreezeRequest> state) { log.info("Restoring database frozen state on startup"); Map<InitiatorType, List<FreezeRequest>> requestsByInitiator = state.stream().collect(groupingBy(FreezeRequest::getInitiatorType)); for (FreezeRequest request : state) { log.warn("Database was frozen by {} process '{}' at {}", request.getInitiatorType(), request.getInitiatorId(), request.getTimestamp().withZone(DateTimeZone.getDefault())); } if (nodeAccess.isClustered()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } else { for (FreezeRequest request : requestsByInitiator.getOrDefault(SYSTEM, emptyList())) { log.warn("Discarding freeze request by {} process '{}'", request.getInitiatorType(), request.getInitiatorId()); databaseFrozenStateManager.remove(request); } if (!requestsByInitiator.getOrDefault(USER_INITIATED, emptyList()).isEmpty()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } } } @Inject  DatabaseFreezeServiceImpl(final Set<Provider<DatabaseInstance>> providers,
                                   final EventManager eventManager,
                                   final DatabaseFrozenStateManager databaseFrozenStateManager,
                                   final Provider<OServer> server,
                                   final NodeAccess nodeAccess,
                                   final SecurityHelper securityHelper,
                                   final List<Freezable> freezables); @Override @Guarded(by = STARTED) boolean isFrozen(); @Override @Guarded(by = STARTED) void checkUnfrozen(); @Override @Guarded(by = STARTED) void checkUnfrozen(final String message); @Override @Guarded(by = STARTED) synchronized FreezeRequest requestFreeze(final InitiatorType type, final String initiatorId); @Override @Guarded(by = STARTED) List<FreezeRequest> getState(); @Override @Guarded(by = STARTED) synchronized boolean releaseRequest(final FreezeRequest request); @Override @Guarded(by = STARTED) synchronized boolean releaseUserInitiatedIfPresent(); @Override synchronized List<FreezeRequest> releaseAllRequests(); @Override synchronized void freezeLocalDatabases(); @Override synchronized void releaseLocalDatabases(); @Override ReadOnlyState getReadOnlyState(); @Subscribe void onNodeMerged(final NodeMergedEvent event); }
DatabaseFreezeServiceImpl extends StateGuardLifecycleSupport implements DatabaseFreezeService, EventAware, EventAware.Asynchronous { @VisibleForTesting void refreezeOnStartup(final List<FreezeRequest> state) { log.info("Restoring database frozen state on startup"); Map<InitiatorType, List<FreezeRequest>> requestsByInitiator = state.stream().collect(groupingBy(FreezeRequest::getInitiatorType)); for (FreezeRequest request : state) { log.warn("Database was frozen by {} process '{}' at {}", request.getInitiatorType(), request.getInitiatorId(), request.getTimestamp().withZone(DateTimeZone.getDefault())); } if (nodeAccess.isClustered()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } else { for (FreezeRequest request : requestsByInitiator.getOrDefault(SYSTEM, emptyList())) { log.warn("Discarding freeze request by {} process '{}'", request.getInitiatorType(), request.getInitiatorId()); databaseFrozenStateManager.remove(request); } if (!requestsByInitiator.getOrDefault(USER_INITIATED, emptyList()).isEmpty()) { log.warn("Databases must be unfrozen manually"); freezeLocalDatabases(); } } } @Inject  DatabaseFreezeServiceImpl(final Set<Provider<DatabaseInstance>> providers,
                                   final EventManager eventManager,
                                   final DatabaseFrozenStateManager databaseFrozenStateManager,
                                   final Provider<OServer> server,
                                   final NodeAccess nodeAccess,
                                   final SecurityHelper securityHelper,
                                   final List<Freezable> freezables); @Override @Guarded(by = STARTED) boolean isFrozen(); @Override @Guarded(by = STARTED) void checkUnfrozen(); @Override @Guarded(by = STARTED) void checkUnfrozen(final String message); @Override @Guarded(by = STARTED) synchronized FreezeRequest requestFreeze(final InitiatorType type, final String initiatorId); @Override @Guarded(by = STARTED) List<FreezeRequest> getState(); @Override @Guarded(by = STARTED) synchronized boolean releaseRequest(final FreezeRequest request); @Override @Guarded(by = STARTED) synchronized boolean releaseUserInitiatedIfPresent(); @Override synchronized List<FreezeRequest> releaseAllRequests(); @Override synchronized void freezeLocalDatabases(); @Override synchronized void releaseLocalDatabases(); @Override ReadOnlyState getReadOnlyState(); @Subscribe void onNodeMerged(final NodeMergedEvent event); static final String SERVER_NAME; }