Search in sources :

Example 11 with InProgressBackupToken

use of com.palantir.atlasdb.backup.api.InProgressBackupToken in project atlasdb by palantir.

the class AtlasBackupServiceTest method completeBackupReturnsSuccessfulNamespaces.

@Test
public void completeBackupReturnsSuccessfulNamespaces() {
    InProgressBackupToken otherInProgress = inProgressBackupToken(OTHER_NAMESPACE);
    Set<Namespace> namespaces = ImmutableSet.of(NAMESPACE, OTHER_NAMESPACE);
    when(atlasBackupClient.prepareBackup(authHeader, PrepareBackupRequest.of(namespaces))).thenReturn(PrepareBackupResponse.of(ImmutableSet.of(IN_PROGRESS, otherInProgress)));
    when(atlasBackupClient.completeBackup(authHeader, CompleteBackupRequest.of(ImmutableSet.of(IN_PROGRESS, otherInProgress)))).thenReturn(CompleteBackupResponse.of(ImmutableSet.of(completedBackup())));
    atlasBackupService.prepareBackup(namespaces);
    assertThat(atlasBackupService.completeBackup(namespaces)).containsExactly(NAMESPACE);
}
Also used : InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 12 with InProgressBackupToken

use of com.palantir.atlasdb.backup.api.InProgressBackupToken in project atlasdb by palantir.

the class AtlasBackupResourceTest method preparesBackupSuccessfully.

@Test
public void preparesBackupSuccessfully() {
    LockToken lockToken = lockToken();
    when(mockTimelock.lockImmutableTimestamp(any())).thenReturn(LockImmutableTimestampResponse.of(IMMUTABLE_TIMESTAMP, lockToken));
    when(mockTimelock.getFreshTimestamp()).thenReturn(BACKUP_START_TIMESTAMP);
    InProgressBackupToken expectedBackupToken = inProgressBackupToken(lockToken);
    assertThat(AtlasFutures.getUnchecked(atlasBackupService.prepareBackup(AUTH_HEADER, PREPARE_BACKUP_REQUEST))).isEqualTo(prepareBackupResponseWith(expectedBackupToken));
    verify(authHeaderValidator).suppliedHeaderMatchesConfig(AUTH_HEADER);
}
Also used : LockToken(com.palantir.lock.v2.LockToken) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Test(org.junit.Test)

Example 13 with InProgressBackupToken

use of com.palantir.atlasdb.backup.api.InProgressBackupToken in project atlasdb by palantir.

the class AtlasBackupResourceTest method validBackupToken.

private InProgressBackupToken validBackupToken() {
    LockToken lockToken = lockToken();
    InProgressBackupToken backupToken = inProgressBackupToken(lockToken);
    Set<LockToken> singleLockToken = ImmutableSet.of(lockToken);
    when(mockTimelock.unlock(singleLockToken)).thenReturn(Futures.immediateFuture(singleLockToken));
    return backupToken;
}
Also used : LockToken(com.palantir.lock.v2.LockToken) InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken)

Example 14 with InProgressBackupToken

use of com.palantir.atlasdb.backup.api.InProgressBackupToken in project atlasdb by palantir.

the class ExternalBackupPersisterTest method putAndGetImmutableTimestamp.

@Test
public void putAndGetImmutableTimestamp() {
    long immutableTimestamp = 1337L;
    InProgressBackupToken inProgressBackupToken = InProgressBackupToken.builder().namespace(NAMESPACE).immutableTimestamp(immutableTimestamp).backupStartTimestamp(3141L).lockToken(LockToken.of(UUID.randomUUID())).build();
    externalBackupPersister.storeImmutableTimestamp(ATLAS_SERVICE, inProgressBackupToken);
    assertThat(externalBackupPersister.getImmutableTimestamp(ATLAS_SERVICE)).contains(immutableTimestamp);
}
Also used : InProgressBackupToken(com.palantir.atlasdb.backup.api.InProgressBackupToken) Test(org.junit.Test)

Example 15 with InProgressBackupToken

use of com.palantir.atlasdb.backup.api.InProgressBackupToken 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)

Aggregations

InProgressBackupToken (com.palantir.atlasdb.backup.api.InProgressBackupToken)15 Test (org.junit.Test)9 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)5 Namespace (com.palantir.atlasdb.timelock.api.Namespace)5 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)4 LockToken (com.palantir.lock.v2.LockToken)4 CompleteBackupRequest (com.palantir.atlasdb.backup.api.CompleteBackupRequest)3 CompleteBackupResponse (com.palantir.atlasdb.backup.api.CompleteBackupResponse)3 NamedThreadFactory (com.palantir.common.concurrent.NamedThreadFactory)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Sets (com.google.common.collect.Sets)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 AtlasBackupClient (com.palantir.atlasdb.backup.api.AtlasBackupClient)2 AtlasBackupClientBlocking (com.palantir.atlasdb.backup.api.AtlasBackupClientBlocking)2 PrepareBackupRequest (com.palantir.atlasdb.backup.api.PrepareBackupRequest)2 PrepareBackupResponse (com.palantir.atlasdb.backup.api.PrepareBackupResponse)2 RefreshBackupRequest (com.palantir.atlasdb.backup.api.RefreshBackupRequest)2