@Test public void isFrozenHAUsesServerRole() { when(nodeAccess.isClustered()).thenReturn(true); when(distributedConfiguration.getServerRole(any())).thenReturn(ROLES.MASTER); assertThat(underTest.isFrozen(), is(false)); when(distributedConfiguration.getServerRole(any())).thenReturn(ROLES.REPLICA); assertThat(underTest.isFrozen(), is(true)); }
@Override @Guarded(by = STARTED) public boolean isFrozen() { if (nodeAccess.isClustered()) { ODistributedServerManager serverManager = distributedServerManagerProvider.get(); Map<String, ROLES> roles = new HashMap<>(); for (String database : serverManager.getMessageService().getDatabases()) { ODistributedConfiguration configuration = serverManager.getDatabaseConfiguration(database); roles.put(database, configuration.getServerRole(SERVER_NAME)); } return roles.values().stream().allMatch(r -> ROLES.REPLICA.equals(r)); } else { return providers.stream().allMatch(provider -> provider.get().isFrozen()); } }
DatabaseFreezeServiceImpl extends StateGuardLifecycleSupport implements DatabaseFreezeService, EventAware, EventAware.Asynchronous { @Override @Guarded(by = STARTED) public boolean isFrozen() { if (nodeAccess.isClustered()) { ODistributedServerManager serverManager = distributedServerManagerProvider.get(); Map<String, ROLES> roles = new HashMap<>(); for (String database : serverManager.getMessageService().getDatabases()) { ODistributedConfiguration configuration = serverManager.getDatabaseConfiguration(database); roles.put(database, configuration.getServerRole(SERVER_NAME)); } return roles.values().stream().allMatch(r -> ROLES.REPLICA.equals(r)); } else { return providers.stream().allMatch(provider -> provider.get().isFrozen()); } } }
DatabaseFreezeServiceImpl extends StateGuardLifecycleSupport implements DatabaseFreezeService, EventAware, EventAware.Asynchronous { @Override @Guarded(by = STARTED) public boolean isFrozen() { if (nodeAccess.isClustered()) { ODistributedServerManager serverManager = distributedServerManagerProvider.get(); Map<String, ROLES> roles = new HashMap<>(); for (String database : serverManager.getMessageService().getDatabases()) { ODistributedConfiguration configuration = serverManager.getDatabaseConfiguration(database); roles.put(database, configuration.getServerRole(SERVER_NAME)); } return roles.values().stream().allMatch(r -> ROLES.REPLICA.equals(r)); } else { return providers.stream().allMatch(provider -> provider.get().isFrozen()); } } @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 { @Override @Guarded(by = STARTED) public boolean isFrozen() { if (nodeAccess.isClustered()) { ODistributedServerManager serverManager = distributedServerManagerProvider.get(); Map<String, ROLES> roles = new HashMap<>(); for (String database : serverManager.getMessageService().getDatabases()) { ODistributedConfiguration configuration = serverManager.getDatabaseConfiguration(database); roles.put(database, configuration.getServerRole(SERVER_NAME)); } return roles.values().stream().allMatch(r -> ROLES.REPLICA.equals(r)); } else { return providers.stream().allMatch(provider -> provider.get().isFrozen()); } } @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 { @Override @Guarded(by = STARTED) public boolean isFrozen() { if (nodeAccess.isClustered()) { ODistributedServerManager serverManager = distributedServerManagerProvider.get(); Map<String, ROLES> roles = new HashMap<>(); for (String database : serverManager.getMessageService().getDatabases()) { ODistributedConfiguration configuration = serverManager.getDatabaseConfiguration(database); roles.put(database, configuration.getServerRole(SERVER_NAME)); } return roles.values().stream().allMatch(r -> ROLES.REPLICA.equals(r)); } else { return providers.stream().allMatch(provider -> provider.get().isFrozen()); } } @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; }