Search in sources :

Example 6 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class TransactionManagersTest method verifyFeedbackIsReportedToService.

private void verifyFeedbackIsReportedToService() {
    AuthHeader authHeader = AuthHeader.valueOf("Bearer omitted");
    SettableRefreshable<AtlasDbRuntimeConfig> refreshableRuntimeConfig = Refreshable.create(mockAtlasDbRuntimeConfig);
    Refreshable<List<TimeLockClientFeedbackService>> timeLockClientFeedbackServices = TransactionManagers.getTimeLockClientFeedbackServices(config, refreshableRuntimeConfig, USER_AGENT, DialogueClients.create(Refreshable.only(ServicesConfigBlock.builder().build())));
    ConjureTimeLockClientFeedback feedbackReport = ConjureTimeLockClientFeedback.builder().atlasVersion("1.0").serviceName("service").nodeId(UUID.randomUUID()).build();
    assertThat(timeLockClientFeedbackServices.current()).hasSize(1);
    timeLockClientFeedbackServices.current().get(0).reportFeedback(authHeader, feedbackReport);
    List<LoggedRequest> requests = findAll(postRequestedFor(urlMatching(FEEDBACK_PATH)));
    assertThat(requests).hasSize(1);
    availableServer.verify(postRequestedFor(urlMatching(FEEDBACK_PATH)).withHeader("Authorization", containing("Bearer omitted")));
    /* config with no servers */
    timeLockRuntimeConfig = getTimelockRuntimeConfig(ImmutableList.of());
    mockAtlasDbRuntimeConfig = mock(AtlasDbRuntimeConfig.class);
    when(mockAtlasDbRuntimeConfig.timelockRuntime()).thenReturn(Optional.of(timeLockRuntimeConfig));
    refreshableRuntimeConfig.update(mockAtlasDbRuntimeConfig);
    assertThat(timeLockClientFeedbackServices.current()).isEmpty();
}
Also used : AuthHeader(com.palantir.tokens.auth.AuthHeader) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) ConjureTimeLockClientFeedback(com.palantir.timelock.feedback.ConjureTimeLockClientFeedback) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig) ImmutableAtlasDbRuntimeConfig(com.palantir.atlasdb.config.ImmutableAtlasDbRuntimeConfig)

Example 7 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class AtlasRestoreServiceTest method restoresToNewAtlasServiceCorrectly.

@Test
public void restoresToNewAtlasServiceCorrectly() {
    RestoreRequest restoreRequest = RestoreRequest.builder().oldAtlasService(WITH_BACKUP).newAtlasService(NO_BACKUP).build();
    // prepare
    DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP_NS), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
    Set<AtlasService> disabledAtlasServices = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
    assertThat(disabledAtlasServices).containsExactly(NO_BACKUP);
    // repair
    BiConsumer<String, RangesForRepair> doNothingConsumer = (_unused1, _unused2) -> {
    };
    Set<AtlasService> repairedAtlasServices = atlasRestoreService.repairInternalTables(ImmutableSet.of(restoreRequest), doNothingConsumer);
    assertThat(repairedAtlasServices).containsExactly(NO_BACKUP);
    verify(cassandraRepairHelper).repairInternalTables(NO_BACKUP, doNothingConsumer);
    verify(cassandraRepairHelper).repairTransactionsTables(eq(NO_BACKUP), anyList(), eq(doNothingConsumer));
    verify(cassandraRepairHelper).cleanTransactionsTables(eq(NO_BACKUP), eq(BACKUP_START_TIMESTAMP), anyList());
    verifyNoMoreInteractions(cassandraRepairHelper);
    // complete
    CompletedBackup completedBackup = backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow();
    CompleteRestoreRequest completeRestoreRequest = CompleteRestoreRequest.of(ImmutableMap.of(NO_BACKUP_NS, completedBackup));
    when(atlasRestoreClient.completeRestore(authHeader, completeRestoreRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(NO_BACKUP_NS)));
    ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP_NS), BACKUP_ID);
    Set<AtlasService> completedAtlasServices = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
    assertThat(completedAtlasServices).containsExactly(NO_BACKUP);
    verify(atlasRestoreClient).completeRestore(authHeader, completeRestoreRequest);
    verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
Also used : RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) CassandraRepairHelper(com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper) CompleteRestoreResponse(com.palantir.atlasdb.backup.api.CompleteRestoreResponse) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) RunWith(org.junit.runner.RunWith) AuthHeader(com.palantir.tokens.auth.AuthHeader) ServiceId(com.palantir.atlasdb.backup.api.ServiceId) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) InOrder(org.mockito.InOrder) ImmutableMap(com.google.common.collect.ImmutableMap) KeyedStream(com.palantir.common.streams.KeyedStream) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) SafeIllegalArgumentException(com.palantir.logsafe.exceptions.SafeIllegalArgumentException) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) RangesForRepair(com.palantir.atlasdb.cassandra.backup.RangesForRepair) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Assertions.assertThatLoggableExceptionThrownBy(com.palantir.logsafe.testing.Assertions.assertThatLoggableExceptionThrownBy) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Optional(java.util.Optional) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) ReenableNamespacesRequest(com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Test(org.junit.Test)

Example 8 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class AtlasBackupService method prepareBackup.

public Set<AtlasService> prepareBackup(Set<AtlasService> atlasServices) {
    throwIfClosed(atlasServices);
    Set<AtlasService> inProgressAndProposedBackups = Sets.union(atlasServices, inProgressBackups.keySet());
    AtlasServices.throwIfAtlasServicesCollide(inProgressAndProposedBackups);
    Map<Namespace, AtlasService> namespaceToServices = KeyedStream.of(atlasServices).mapKeys(AtlasService::getNamespace).collectToMap();
    PrepareBackupRequest request = PrepareBackupRequest.of(namespaceToServices.keySet());
    PrepareBackupResponse response = atlasBackupClient.prepareBackup(authHeader, request);
    Map<AtlasService, InProgressBackupToken> tokensPerService = KeyedStream.of(response.getSuccessful()).mapKeys(token -> namespaceToServices.get(token.getNamespace())).collectToMap();
    KeyedStream.stream(tokensPerService).forEach(this::storeBackupToken);
    return tokensPerService.keySet();
}
Also used : PrepareBackupResponse(com.palantir.atlasdb.backup.api.PrepareBackupResponse) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) AtlasBackupClientBlocking(com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking) AuthHeader(com.palantir.tokens.auth.AuthHeader) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) Function(java.util.function.Function) SafeLogger(com.palantir.logsafe.logger.SafeLogger) SafeArg(com.palantir.logsafe.SafeArg) CompleteBackupResponse(com.palantir.atlasdb.backup.api.CompleteBackupResponse) PTExecutors(com.palantir.common.concurrent.PTExecutors) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AtlasFutures(com.palantir.atlasdb.futures.AtlasFutures) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Refreshable(com.palantir.refreshable.Refreshable) ImmutableSet(com.google.common.collect.ImmutableSet) NamedThreadFactory(com.palantir.common.concurrent.NamedThreadFactory) CompleteBackupRequest(com.palantir.atlasdb.backup.api.CompleteBackupRequest) KeyedStream(com.palantir.common.streams.KeyedStream) PrepareBackupRequest(com.palantir.atlasdb.backup.api.PrepareBackupRequest) ReloadingFactory(com.palantir.dialogue.clients.DialogueClients.ReloadingFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) RefreshBackupRequest(com.palantir.atlasdb.backup.api.RefreshBackupRequest) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) Futures(com.google.common.util.concurrent.Futures) LockLeaseRefresher(com.palantir.lock.v2.LockLeaseRefresher) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) AtlasDbRemotingConstants(com.palantir.atlasdb.http.AtlasDbRemotingConstants) Closeable(java.io.Closeable) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DialogueClients(com.palantir.dialogue.clients.DialogueClients) LockRefresher(com.palantir.lock.client.LockRefresher) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) PrepareBackupResponse(com.palantir.atlasdb.backup.api.PrepareBackupResponse) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Namespace(com.palantir.atlasdb.timelock.api.Namespace) PrepareBackupRequest(com.palantir.atlasdb.backup.api.PrepareBackupRequest)

Example 9 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class AtlasDbEteServer method createAndRegisterBackupAndRestoreResource.

private void createAndRegisterBackupAndRestoreResource(AtlasDbEteConfiguration config, Environment environment, TransactionManager txManager, TaggedMetricRegistry taggedMetrics) throws IOException {
    AuthHeader authHeader = AuthHeader.of(BearerToken.valueOf("test-auth"));
    URL localServer = new URL("https://localhost:1234");
    Path backupFolder = Paths.get("/var/data/backup");
    Files.createDirectories(backupFolder);
    Function<AtlasService, Path> backupFolderFactory = _unused -> backupFolder;
    ExternalBackupPersister externalBackupPersister = new ExternalBackupPersister(backupFolderFactory);
    Function<String, BackupTimeLockServiceView> timelockServices = _unused -> createBackupTimeLockServiceView(txManager);
    AuthHeaderValidator authHeaderValidator = new AuthHeaderValidator(() -> Optional.of(authHeader.getBearerToken()));
    RedirectRetryTargeter redirectRetryTargeter = RedirectRetryTargeter.create(localServer, ImmutableList.of(localServer));
    AtlasBackupClient atlasBackupClient = AtlasBackupResource.jersey(authHeaderValidator, redirectRetryTargeter, timelockServices);
    AtlasRestoreClient atlasRestoreClient = AtlasRestoreResource.jersey(authHeaderValidator, redirectRetryTargeter, timelockServices);
    Refreshable<ServerListConfig> serverListConfig = getServerListConfigForTimeLock(config);
    TimeLockManagementService timeLockManagementService = getRemoteTimeLockManagementService(serverListConfig, taggedMetrics);
    AtlasBackupService atlasBackupService = AtlasBackupService.createForTests(authHeader, atlasBackupClient, txManager, backupFolderFactory);
    Function<AtlasService, CassandraKeyValueServiceConfig> keyValueServiceConfigFactory = _unused -> (CassandraKeyValueServiceConfig) config.getAtlasDbConfig().keyValueService();
    Function<AtlasService, CassandraKeyValueServiceRuntimeConfig> runtimeConfigFactory = _unused -> (CassandraKeyValueServiceRuntimeConfig) config.getAtlasDbRuntimeConfig().flatMap(AtlasDbRuntimeConfig::keyValueService).orElseThrow();
    Function<AtlasService, CassandraClusterConfig> cassandraClusterConfigFactory = atlasService -> CassandraClusterConfig.of(keyValueServiceConfigFactory.apply(atlasService), runtimeConfigFactory.apply(atlasService));
    Function<AtlasService, Refreshable<CassandraServersConfig>> refreshableCassandraServersConfigFactory = runtimeConfigFactory.andThen(runtimeConfig -> Refreshable.only(runtimeConfig.servers()));
    AtlasRestoreService atlasRestoreService = AtlasRestoreService.createForTests(authHeader, atlasRestoreClient, timeLockManagementService, externalBackupPersister, txManager, cassandraClusterConfigFactory, refreshableCassandraServersConfigFactory);
    environment.jersey().register(new SimpleBackupAndRestoreResource(atlasBackupService, atlasRestoreService, externalBackupPersister));
}
Also used : TransactionService(com.palantir.atlasdb.transaction.service.TransactionService) ServerListConfigs(com.palantir.atlasdb.config.ServerListConfigs) NotInitializedExceptionMapper(com.palantir.atlasdb.http.NotInitializedExceptionMapper) LongSupplier(java.util.function.LongSupplier) SimpleLockResource(com.palantir.atlasdb.lock.SimpleLockResource) URL(java.net.URL) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) AuthHeader(com.palantir.tokens.auth.AuthHeader) BlobSchema(com.palantir.atlasdb.blob.BlobSchema) TargetedSweepFollower(com.palantir.atlasdb.sweep.queue.TargetedSweepFollower) SimpleTodoResource(com.palantir.atlasdb.todo.SimpleTodoResource) RedirectRetryTargeter(com.palantir.atlasdb.http.RedirectRetryTargeter) AtlasBackupService(com.palantir.atlasdb.backup.AtlasBackupService) UserAgent(com.palantir.conjure.java.api.config.service.UserAgent) TransactionServices(com.palantir.atlasdb.transaction.service.TransactionServices) CoordinationServices(com.palantir.atlasdb.internalschema.persistence.CoordinationServices) SweepTaskRunner(com.palantir.atlasdb.sweep.SweepTaskRunner) Path(java.nio.file.Path) InternalSchemaMetadata(com.palantir.atlasdb.internalschema.InternalSchemaMetadata) CassandraServersConfig(com.palantir.atlasdb.cassandra.CassandraServersConfigs.CassandraServersConfig) Refreshable(com.palantir.refreshable.Refreshable) Application(io.dropwizard.Application) ImmutableSet(com.google.common.collect.ImmutableSet) TimestampManagementService(com.palantir.timestamp.TimestampManagementService) CoordinationService(com.palantir.atlasdb.coordination.CoordinationService) AtlasDbDialogueServiceProvider(com.palantir.atlasdb.factory.AtlasDbDialogueServiceProvider) BackupTimeLockServiceView(com.palantir.atlasdb.timelock.BackupTimeLockServiceView) SharedMetricRegistries(com.codahale.metrics.SharedMetricRegistries) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) MetricsManagers(com.palantir.atlasdb.util.MetricsManagers) ServicesConfigBlock(com.palantir.conjure.java.api.config.service.ServicesConfigBlock) SimpleBackupAndRestoreResource(com.palantir.atlasdb.backup.SimpleBackupAndRestoreResource) Response(javax.ws.rs.core.Response) AtlasBackupResource(com.palantir.atlasdb.backup.AtlasBackupResource) AtlasRestoreService(com.palantir.atlasdb.backup.AtlasRestoreService) Optional(java.util.Optional) SpecialTimestampsSupplier(com.palantir.atlasdb.sweep.queue.SpecialTimestampsSupplier) SimpleEteTimestampResource(com.palantir.atlasdb.timestamp.SimpleEteTimestampResource) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) TodoClient(com.palantir.atlasdb.todo.TodoClient) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) SafeLoggerFactory(com.palantir.logsafe.logger.SafeLoggerFactory) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient) Bootstrap(io.dropwizard.setup.Bootstrap) Stopwatch(com.google.common.base.Stopwatch) TodoSchema(com.palantir.atlasdb.todo.TodoSchema) ExternalBackupPersister(com.palantir.atlasdb.backup.ExternalBackupPersister) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TransactionManagers(com.palantir.atlasdb.factory.TransactionManagers) SafeLogger(com.palantir.logsafe.logger.SafeLogger) AtlasRestoreResource(com.palantir.atlasdb.backup.AtlasRestoreResource) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) BearerToken(com.palantir.tokens.auth.BearerToken) SubstitutingSourceProvider(io.dropwizard.configuration.SubstitutingSourceProvider) ImmutableList(com.google.common.collect.ImmutableList) EnvironmentVariableSubstitutor(io.dropwizard.configuration.EnvironmentVariableSubstitutor) TransactionSchemaVersionEnforcement(com.palantir.atlasdb.transaction.impl.TransactionSchemaVersionEnforcement) Suppliers(com.google.common.base.Suppliers) SimpleCoordinationResource(com.palantir.atlasdb.coordination.SimpleCoordinationResource) SharedTaggedMetricRegistries(com.palantir.tritium.metrics.registry.SharedTaggedMetricRegistries) Environment(io.dropwizard.setup.Environment) Files(java.nio.file.Files) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) TargetedSweeper(com.palantir.atlasdb.sweep.queue.TargetedSweeper) IOException(java.io.IOException) TransactionSchemaManager(com.palantir.atlasdb.internalschema.TransactionSchemaManager) TimelockService(com.palantir.lock.v2.TimelockService) TaggedMetricRegistry(com.palantir.tritium.metrics.registry.TaggedMetricRegistry) DelegatingBackupTimeLockServiceView(com.palantir.atlasdb.backup.DelegatingBackupTimeLockServiceView) TimeUnit(java.util.concurrent.TimeUnit) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig) EmptyOptionalException(io.dropwizard.jersey.optional.EmptyOptionalException) Follower(com.palantir.atlasdb.cleaner.Follower) Paths(java.nio.file.Paths) KeyValueService(com.palantir.atlasdb.keyvalue.api.KeyValueService) ConjureJerseyFeature(com.palantir.conjure.java.server.jersey.ConjureJerseyFeature) AtlasDbRemotingConstants(com.palantir.atlasdb.http.AtlasDbRemotingConstants) CellsSweeper(com.palantir.atlasdb.sweep.CellsSweeper) AuthHeaderValidator(com.palantir.atlasdb.backup.AuthHeaderValidator) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DialogueClients(com.palantir.dialogue.clients.DialogueClients) Schema(com.palantir.atlasdb.table.description.Schema) CleanupFollower(com.palantir.atlasdb.cleaner.CleanupFollower) AtlasDbConfig(com.palantir.atlasdb.config.AtlasDbConfig) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) TimeLockManagementService(com.palantir.atlasdb.timelock.api.management.TimeLockManagementService) URL(java.net.URL) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) Path(java.nio.file.Path) ExternalBackupPersister(com.palantir.atlasdb.backup.ExternalBackupPersister) SimpleBackupAndRestoreResource(com.palantir.atlasdb.backup.SimpleBackupAndRestoreResource) AuthHeader(com.palantir.tokens.auth.AuthHeader) BackupTimeLockServiceView(com.palantir.atlasdb.timelock.BackupTimeLockServiceView) DelegatingBackupTimeLockServiceView(com.palantir.atlasdb.backup.DelegatingBackupTimeLockServiceView) CassandraClusterConfig(com.palantir.atlasdb.keyvalue.cassandra.async.client.creation.ClusterFactory.CassandraClusterConfig) Refreshable(com.palantir.refreshable.Refreshable) AtlasRestoreClient(com.palantir.atlasdb.backup.api.AtlasRestoreClient) RedirectRetryTargeter(com.palantir.atlasdb.http.RedirectRetryTargeter) ServerListConfig(com.palantir.atlasdb.config.ServerListConfig) AuthHeaderValidator(com.palantir.atlasdb.backup.AuthHeaderValidator) AtlasBackupClient(com.palantir.atlasdb.backup.api.AtlasBackupClient) AtlasRestoreService(com.palantir.atlasdb.backup.AtlasRestoreService) AtlasBackupService(com.palantir.atlasdb.backup.AtlasBackupService) AtlasDbRuntimeConfig(com.palantir.atlasdb.config.AtlasDbRuntimeConfig)

Example 10 with AuthHeader

use of com.palantir.tokens.auth.AuthHeader in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method directLegacyAndConjureLockServicesInteractCorrectly.

@Test
public void directLegacyAndConjureLockServicesInteractCorrectly() throws InterruptedException {
    LockRefreshToken token = client.legacyLockService().lock("tom", com.palantir.lock.LockRequest.builder(ImmutableSortedMap.<LockDescriptor, LockMode>naturalOrder().put(StringLockDescriptor.of("lock"), LockMode.WRITE).build()).build());
    ConjureLockRefreshToken conjureAnalogue = ConjureLockRefreshToken.of(token.getTokenId(), token.getExpirationDateMs());
    // Cannot assert equality because tokens can have different expiration dates.
    assertThat(client.legacyLockService().refreshLockRefreshTokens(ImmutableList.of(token))).as("refreshing a live token should succeed").hasOnlyOneElementSatisfying(refreshed -> assertThat(refreshed.getTokenId()).isEqualTo(refreshed.getTokenId()));
    AuthHeader authHeader = AuthHeader.valueOf("Bearer unused");
    assertThat(client.conjureLegacyLockService().refreshLockRefreshTokens(authHeader, client.namespace(), ImmutableList.of(conjureAnalogue))).as("it is possible to refresh a live token through the conjure API").hasOnlyOneElementSatisfying(refreshed -> assertThat(refreshed.getTokenId()).isEqualTo(refreshed.getTokenId()));
    ConjureSimpleHeldLocksToken conjureHeldLocksToken = ConjureSimpleHeldLocksToken.of(token.getTokenId(), 0L);
    assertThat(client.conjureLegacyLockService().unlockSimple(authHeader, client.namespace(), conjureHeldLocksToken)).as("it is possible to unlock a live token through the conjure API").isTrue();
    assertThat(client.conjureLegacyLockService().unlockSimple(authHeader, client.namespace(), conjureHeldLocksToken)).as("a token unlocked through the conjure API stays unlocked").isFalse();
    assertThat(client.legacyLockService().unlockSimple(SimpleHeldLocksToken.fromLockRefreshToken(token))).as("a token unlocked through the conjure API stays unlocked even in the legacy API").isFalse();
}
Also used : AuthHeader(com.palantir.tokens.auth.AuthHeader) ConjureSimpleHeldLocksToken(com.palantir.lock.ConjureSimpleHeldLocksToken) ConjureLockRefreshToken(com.palantir.lock.ConjureLockRefreshToken) ConjureLockRefreshToken(com.palantir.lock.ConjureLockRefreshToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Aggregations

AuthHeader (com.palantir.tokens.auth.AuthHeader)13 Optional (java.util.Optional)7 Set (java.util.Set)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)5 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)4 Namespace (com.palantir.atlasdb.timelock.api.Namespace)4 KeyedStream (com.palantir.common.streams.KeyedStream)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 AtlasBackupClient (com.palantir.atlasdb.backup.api.AtlasBackupClient)3 AtlasRestoreClient (com.palantir.atlasdb.backup.api.AtlasRestoreClient)3 AtlasDbRemotingConstants (com.palantir.atlasdb.http.AtlasDbRemotingConstants)3 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)3 TimeLockManagementService (com.palantir.atlasdb.timelock.api.management.TimeLockManagementService)3 TransactionManager (com.palantir.atlasdb.transaction.api.TransactionManager)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2