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();
}
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);
}
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();
}
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));
}
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();
}
Aggregations