Search in sources :

Example 1 with TimelockNamespaces

use of com.palantir.atlasdb.timelock.TimelockNamespaces in project atlasdb by palantir.

the class TimeLockAgent method createAndRegisterResources.

private void createAndRegisterResources() {
    registerTimeLockCorruptionJerseyFilter();
    registerTimeLockCorruptionNotifiers();
    registerPaxosResource();
    registerExceptionMappers();
    registerClientFeedbackService();
    namespaces = new TimelockNamespaces(metricsManager, this::createInvalidatingTimeLockServices, Suppliers.compose(TimeLockRuntimeConfiguration::maxNumberOfClients, runtime::get), DisabledNamespaces.create(sqliteDataSource));
    registerManagementResource();
    // Finally, register the health check, and endpoints associated with the clients.
    TimeLockResource resource = TimeLockResource.create(namespaces);
    healthCheck = paxosResources.leadershipComponents().healthCheck(namespaces::getActiveClients);
    registrar.accept(resource);
    Function<String, LockService> lockServiceGetter = namespace -> namespaces.get(namespace).getLockService();
    Function<String, AsyncTimelockService> asyncTimelockServiceGetter = namespace -> namespaces.get(namespace).getTimelockService();
    Function<String, BackupTimeLockServiceView> backupTimeLockServiceViewGetter = namespace -> namespaces.getForRestore(namespace);
    AuthHeaderValidator authHeaderValidator = getAuthHeaderValidator();
    RedirectRetryTargeter redirectRetryTargeter = redirectRetryTargeter();
    if (undertowRegistrar.isPresent()) {
        Consumer<UndertowService> presentUndertowRegistrar = undertowRegistrar.get();
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, ConjureTimelockResource.undertow(redirectRetryTargeter, asyncTimelockServiceGetter));
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, ConjureLockWatchingResource.undertow(redirectRetryTargeter, asyncTimelockServiceGetter));
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, ConjureLockV1Resource.undertow(redirectRetryTargeter, lockServiceGetter));
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, TimeLockPaxosHistoryProviderResource.undertow(corruptionComponents.localHistoryLoader()));
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, MultiClientConjureTimelockResource.undertow(redirectRetryTargeter, asyncTimelockServiceGetter));
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, AtlasBackupResource.undertow(authHeaderValidator, redirectRetryTargeter, asyncTimelockServiceGetter));
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, AtlasRestoreResource.undertow(authHeaderValidator, redirectRetryTargeter, backupTimeLockServiceViewGetter));
        registerCorruptionHandlerWrappedService(presentUndertowRegistrar, DisabledNamespacesUpdaterResource.undertow(authHeaderValidator, redirectRetryTargeter, namespaces));
    } else {
        registrar.accept(ConjureTimelockResource.jersey(redirectRetryTargeter, asyncTimelockServiceGetter));
        registrar.accept(ConjureLockWatchingResource.jersey(redirectRetryTargeter, asyncTimelockServiceGetter));
        registrar.accept(ConjureLockV1Resource.jersey(redirectRetryTargeter, lockServiceGetter));
        registrar.accept(TimeLockPaxosHistoryProviderResource.jersey(corruptionComponents.localHistoryLoader()));
        registrar.accept(MultiClientConjureTimelockResource.jersey(redirectRetryTargeter, asyncTimelockServiceGetter));
        registrar.accept(AtlasBackupResource.jersey(authHeaderValidator, redirectRetryTargeter, asyncTimelockServiceGetter));
        registrar.accept(AtlasRestoreResource.jersey(authHeaderValidator, redirectRetryTargeter, backupTimeLockServiceViewGetter));
        registrar.accept(DisabledNamespacesUpdaterResource.jersey(authHeaderValidator, redirectRetryTargeter, namespaces));
    }
}
Also used : FeedbackHandler(com.palantir.atlasdb.timelock.adjudicate.FeedbackHandler) URL(java.net.URL) UndertowService(com.palantir.conjure.java.undertow.lib.UndertowService) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AllNodesDisabledNamespacesUpdater(com.palantir.atlasdb.timelock.management.AllNodesDisabledNamespacesUpdater) DatabaseTsBoundPersisterRuntimeConfiguration(com.palantir.timelock.config.DatabaseTsBoundPersisterRuntimeConfiguration) LeaderConfig(com.palantir.atlasdb.config.LeaderConfig) TimeLockInstallConfiguration(com.palantir.timelock.config.TimeLockInstallConfiguration) TsBoundPersisterConfiguration(com.palantir.timelock.config.TsBoundPersisterConfiguration) TimeLockRuntimeConfiguration(com.palantir.timelock.config.TimeLockRuntimeConfiguration) TimeLockActivityCheckerFactory(com.palantir.timelock.invariants.TimeLockActivityCheckerFactory) ConjureLockV1Resource(com.palantir.atlasdb.timelock.lock.v1.ConjureLockV1Resource) RedirectRetryTargeter(com.palantir.atlasdb.http.RedirectRetryTargeter) MetricsManager(com.palantir.atlasdb.util.MetricsManager) PTExecutors(com.palantir.common.concurrent.PTExecutors) DisabledNamespaces(com.palantir.atlasdb.timelock.management.DisabledNamespaces) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) ClusterConfiguration(com.palantir.timelock.config.ClusterConfiguration) Map(java.util.Map) NotCurrentLeaderExceptionMapper(com.palantir.atlasdb.http.NotCurrentLeaderExceptionMapper) ImmutableLeaderConfig(com.palantir.atlasdb.config.ImmutableLeaderConfig) AsyncTimelockService(com.palantir.atlasdb.timelock.AsyncTimelockService) Path(java.nio.file.Path) DatabaseTsBoundPersisterConfiguration(com.palantir.timelock.config.DatabaseTsBoundPersisterConfiguration) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Refreshable(com.palantir.refreshable.Refreshable) ImmutableSet(com.google.common.collect.ImmutableSet) ACCEPTOR_SUBDIRECTORY_PATH(com.palantir.atlasdb.timelock.paxos.PaxosTimeLockConstants.ACCEPTOR_SUBDIRECTORY_PATH) ConjureTimelockResource(com.palantir.atlasdb.timelock.ConjureTimelockResource) OrderableSlsVersion(com.palantir.sls.versions.OrderableSlsVersion) TimeLockClientFeedbackResource(com.palantir.atlasdb.timelock.adjudicate.TimeLockClientFeedbackResource) PersistentNamespaceContexts(com.palantir.atlasdb.timelock.management.PersistentNamespaceContexts) TimeLockManagementResource(com.palantir.atlasdb.timelock.management.TimeLockManagementResource) BackupTimeLockServiceView(com.palantir.atlasdb.timelock.BackupTimeLockServiceView) TimeLockServices(com.palantir.atlasdb.timelock.TimeLockServices) ConjureLockWatchingResource(com.palantir.atlasdb.timelock.ConjureLockWatchingResource) MultiClientConjureTimelockResource(com.palantir.atlasdb.timelock.batch.MultiClientConjureTimelockResource) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) List(java.util.List) AtlasBackupResource(com.palantir.atlasdb.backup.AtlasBackupResource) TooManyRequestsExceptionMapper(com.palantir.atlasdb.timelock.TooManyRequestsExceptionMapper) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Optional(java.util.Optional) Client(com.palantir.paxos.Client) RestrictedTimeLockRuntimeConfiguration(com.palantir.timelock.config.RestrictedTimeLockRuntimeConfiguration) RemotingClientConfigs(com.palantir.atlasdb.config.RemotingClientConfigs) JerseyCorruptionFilter(com.palantir.timelock.corruption.handle.JerseyCorruptionFilter) PaxosResourcesFactory(com.palantir.atlasdb.timelock.paxos.PaxosResourcesFactory) ImmutableServerListConfig(com.palantir.atlasdb.config.ImmutableServerListConfig) PaxosResources(com.palantir.atlasdb.timelock.paxos.PaxosResources) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) HealthStatusReport(com.palantir.atlasdb.timelock.adjudicate.HealthStatusReport) DisabledNamespacesUpdaterResource(com.palantir.atlasdb.timelock.management.DisabledNamespacesUpdaterResource) Function(java.util.function.Function) Supplier(java.util.function.Supplier) SafeLogger(com.palantir.logsafe.logger.SafeLogger) AtlasRestoreResource(com.palantir.atlasdb.backup.AtlasRestoreResource) NoSimultaneousServiceCheck(com.palantir.timelock.invariants.NoSimultaneousServiceCheck) SafeArg(com.palantir.logsafe.SafeArg) TimeLockPersistenceInvariants(com.palantir.timelock.config.TimeLockPersistenceInvariants) BearerToken(com.palantir.tokens.auth.BearerToken) LEARNER_SUBDIRECTORY_PATH(com.palantir.atlasdb.timelock.paxos.PaxosTimeLockConstants.LEARNER_SUBDIRECTORY_PATH) AuxiliaryRemotingParameters(com.palantir.atlasdb.config.AuxiliaryRemotingParameters) Suppliers(com.google.common.base.Suppliers) TimelockNamespaces(com.palantir.atlasdb.timelock.TimelockNamespaces) CorruptionHealthReport(com.palantir.timelock.corruption.detection.CorruptionHealthReport) TimestampStorage(com.palantir.timelock.management.TimestampStorage) TimeLockResource(com.palantir.atlasdb.timelock.TimeLockResource) LeaderElectionMetricAggregator(com.palantir.atlasdb.timelock.adjudicate.LeaderElectionMetricAggregator) ServiceLifecycleController(com.palantir.atlasdb.timelock.management.ServiceLifecycleController) UndertowCorruptionHandlerService(com.palantir.timelock.corruption.handle.UndertowCorruptionHandlerService) PersistenceConfigStore(com.palantir.timelock.store.PersistenceConfigStore) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ImmutableTimelockPaxosInstallationContext(com.palantir.atlasdb.timelock.paxos.ImmutableTimelockPaxosInstallationContext) SqliteBlobStore(com.palantir.timelock.store.SqliteBlobStore) LEADER_PAXOS_NAMESPACE(com.palantir.atlasdb.timelock.paxos.PaxosTimeLockConstants.LEADER_PAXOS_NAMESPACE) CorruptionNotifierResource(com.palantir.timelock.corruption.handle.CorruptionNotifierResource) Consumer(java.util.function.Consumer) PaxosTsBoundPersisterConfiguration(com.palantir.timelock.config.PaxosTsBoundPersisterConfiguration) KeyValueServiceRuntimeConfig(com.palantir.atlasdb.spi.KeyValueServiceRuntimeConfig) LockService(com.palantir.lock.LockService) LockLog(com.palantir.atlasdb.timelock.lock.LockLog) TimeLockCorruptionComponents(com.palantir.atlasdb.timelock.paxos.TimeLockCorruptionComponents) ImmutableTimestampStorage(com.palantir.timelock.management.ImmutableTimestampStorage) ManagedTimestampService(com.palantir.timestamp.ManagedTimestampService) AuthHeaderValidator(com.palantir.atlasdb.backup.AuthHeaderValidator) AllNodesDisabledNamespacesUpdaterFactory(com.palantir.atlasdb.timelock.management.AllNodesDisabledNamespacesUpdaterFactory) TimeLockPaxosHistoryProviderResource(com.palantir.timelock.history.remote.TimeLockPaxosHistoryProviderResource) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BlockingTimeoutExceptionMapper(com.palantir.atlasdb.http.BlockingTimeoutExceptionMapper) DialogueClients(com.palantir.dialogue.clients.DialogueClients) Preconditions(com.palantir.logsafe.Preconditions) ServiceDiscoveringDatabaseTimeLockSupplier(com.palantir.timelock.ServiceDiscoveringDatabaseTimeLockSupplier) LockService(com.palantir.lock.LockService) BackupTimeLockServiceView(com.palantir.atlasdb.timelock.BackupTimeLockServiceView) TimelockNamespaces(com.palantir.atlasdb.timelock.TimelockNamespaces) TimeLockRuntimeConfiguration(com.palantir.timelock.config.TimeLockRuntimeConfiguration) RestrictedTimeLockRuntimeConfiguration(com.palantir.timelock.config.RestrictedTimeLockRuntimeConfiguration) TimeLockResource(com.palantir.atlasdb.timelock.TimeLockResource) RedirectRetryTargeter(com.palantir.atlasdb.http.RedirectRetryTargeter) UndertowService(com.palantir.conjure.java.undertow.lib.UndertowService) AsyncTimelockService(com.palantir.atlasdb.timelock.AsyncTimelockService) AuthHeaderValidator(com.palantir.atlasdb.backup.AuthHeaderValidator)

Example 2 with TimelockNamespaces

use of com.palantir.atlasdb.timelock.TimelockNamespaces in project atlasdb by palantir.

the class TimeLockManagementResourceTest method setup.

@Before
public void setup() throws MalformedURLException {
    URL testUrl = new URL("http", "host", "file");
    RedirectRetryTargeter redirectRetryTargeter = RedirectRetryTargeter.create(testUrl, ImmutableList.of(testUrl));
    Path rootFolderPath = tempFolder.getRoot().toPath();
    PersistentNamespaceContext persistentNamespaceContext = PersistentNamespaceContexts.timestampBoundPaxos(rootFolderPath, SqliteConnections.getDefaultConfiguredPooledDataSource(rootFolderPath));
    DisabledNamespaces disabledNamespaces = mock(DisabledNamespaces.class);
    TimelockNamespaces namespaces = new TimelockNamespaces(metricsManager, serviceFactory, maxNumberOfClientsSupplier, disabledNamespaces);
    when(authHeaderValidator.suppliedHeaderMatchesConfig(AUTH_HEADER)).thenReturn(true);
    when(authHeaderValidator.suppliedHeaderMatchesConfig(WRONG_AUTH_HEADER)).thenReturn(false);
    timeLockManagementResource = TimeLockManagementResource.create(persistentNamespaceContext, namespaces, allNodesDisabledNamespacesUpdater, authHeaderValidator, redirectRetryTargeter, new ServiceLifecycleController(serviceStopper, PTExecutors.newSingleThreadScheduledExecutor()));
    createDirectoryForLeaderForEachClientUseCase(NAMESPACE_1);
    createDirectoryInRootDataDirectory(NAMESPACE_2);
}
Also used : Path(java.nio.file.Path) TimelockNamespaces(com.palantir.atlasdb.timelock.TimelockNamespaces) URL(java.net.URL) RedirectRetryTargeter(com.palantir.atlasdb.http.RedirectRetryTargeter) Before(org.junit.Before)

Aggregations

RedirectRetryTargeter (com.palantir.atlasdb.http.RedirectRetryTargeter)2 TimelockNamespaces (com.palantir.atlasdb.timelock.TimelockNamespaces)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Suppliers (com.google.common.base.Suppliers)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 AtlasBackupResource (com.palantir.atlasdb.backup.AtlasBackupResource)1 AtlasRestoreResource (com.palantir.atlasdb.backup.AtlasRestoreResource)1 AuthHeaderValidator (com.palantir.atlasdb.backup.AuthHeaderValidator)1 AuxiliaryRemotingParameters (com.palantir.atlasdb.config.AuxiliaryRemotingParameters)1 ImmutableLeaderConfig (com.palantir.atlasdb.config.ImmutableLeaderConfig)1 ImmutableServerListConfig (com.palantir.atlasdb.config.ImmutableServerListConfig)1 LeaderConfig (com.palantir.atlasdb.config.LeaderConfig)1 RemotingClientConfigs (com.palantir.atlasdb.config.RemotingClientConfigs)1 ServerListConfig (com.palantir.atlasdb.config.ServerListConfig)1 BlockingTimeoutExceptionMapper (com.palantir.atlasdb.http.BlockingTimeoutExceptionMapper)1 NotCurrentLeaderExceptionMapper (com.palantir.atlasdb.http.NotCurrentLeaderExceptionMapper)1 KeyValueServiceRuntimeConfig (com.palantir.atlasdb.spi.KeyValueServiceRuntimeConfig)1 AsyncTimelockService (com.palantir.atlasdb.timelock.AsyncTimelockService)1