use of com.palantir.atlasdb.backup.api.CompleteRestoreRequest in project atlasdb by palantir.
the class AtlasRestoreServiceTest method restoresToNewNamespaceCorrectly.
@Test
public void restoresToNewNamespaceCorrectly() {
RestoreRequest restoreRequest = RestoreRequest.builder().oldNamespace(WITH_BACKUP).newNamespace(NO_BACKUP).build();
// prepare
DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
Set<Namespace> disabledNamespaces = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(disabledNamespaces).containsExactly(NO_BACKUP);
// repair
BiConsumer<String, RangesForRepair> doNothingConsumer = (_unused1, _unused2) -> {
};
Set<Namespace> repairedNamespaces = atlasRestoreService.repairInternalTables(ImmutableSet.of(restoreRequest), doNothingConsumer);
assertThat(repairedNamespaces).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, completedBackup));
when(atlasRestoreClient.completeRestore(authHeader, completeRestoreRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(NO_BACKUP)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(NO_BACKUP), BACKUP_ID);
Set<Namespace> completedNamespaces = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest), BACKUP_ID);
assertThat(completedNamespaces).containsExactly(NO_BACKUP);
verify(atlasRestoreClient).completeRestore(authHeader, completeRestoreRequest);
verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
use of com.palantir.atlasdb.backup.api.CompleteRestoreRequest in project atlasdb by palantir.
the class AtlasRestoreResourceTest method throwsIfWrongAuthHeaderIsProvided.
@Test
public void throwsIfWrongAuthHeaderIsProvided() {
CompletedBackup completedBackup = completedBackup();
AuthHeader wrongHeader = AuthHeader.of(BearerToken.valueOf("imposter"));
CompleteRestoreRequest request = CompleteRestoreRequest.of(ImmutableMap.of(NAMESPACE, completedBackup));
assertThatServiceExceptionThrownBy(() -> AtlasFutures.getUnchecked(atlasRestoreResource.completeRestore(wrongHeader, request))).hasType(ErrorType.PERMISSION_DENIED);
}
use of com.palantir.atlasdb.backup.api.CompleteRestoreRequest 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.atlasdb.backup.api.CompleteRestoreRequest in project atlasdb by palantir.
the class AtlasRestoreServiceTest method completeRestoreReturnsSuccessfulNamespaces.
@Test
public void completeRestoreReturnsSuccessfulNamespaces() {
Set<AtlasService> atlasServices = ImmutableSet.of(WITH_BACKUP, FAILING_NAMESPACE);
Map<Namespace, CompletedBackup> completedBackups = KeyedStream.of(atlasServices).map(backupPersister::getCompletedBackup).flatMap(Optional::stream).mapKeys(AtlasService::getNamespace).collectToMap();
CompleteRestoreRequest request = CompleteRestoreRequest.of(completedBackups);
when(atlasRestoreClient.completeRestore(authHeader, request)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(WITH_BACKUP_NS)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP_NS), BACKUP_ID);
Set<RestoreRequest> requests = atlasServices.stream().map(this::restoreRequest).collect(Collectors.toSet());
Set<AtlasService> successfulAtlasServices = atlasRestoreService.completeRestore(requests, BACKUP_ID);
assertThat(successfulAtlasServices).containsExactly(WITH_BACKUP);
verify(atlasRestoreClient).completeRestore(authHeader, request);
verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
use of com.palantir.atlasdb.backup.api.CompleteRestoreRequest in project atlasdb by palantir.
the class AtlasRestoreServiceTest method completesRestoreAfterFastForwardingTimestamp.
@Test
public void completesRestoreAfterFastForwardingTimestamp() {
Map<Namespace, CompletedBackup> completedBackups = ImmutableMap.of(WITH_BACKUP_NS, backupPersister.getCompletedBackup(WITH_BACKUP).orElseThrow());
CompleteRestoreRequest completeRequest = CompleteRestoreRequest.of(completedBackups);
when(atlasRestoreClient.completeRestore(authHeader, completeRequest)).thenReturn(CompleteRestoreResponse.of(ImmutableSet.of(WITH_BACKUP_NS)));
ReenableNamespacesRequest reenableRequest = ReenableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP_NS), BACKUP_ID);
Set<AtlasService> successfulAtlasServices = atlasRestoreService.completeRestore(ImmutableSet.of(restoreRequest(WITH_BACKUP)), BACKUP_ID);
assertThat(successfulAtlasServices).containsExactly(WITH_BACKUP);
InOrder inOrder = Mockito.inOrder(atlasRestoreClient, timeLockManagementService);
inOrder.verify(atlasRestoreClient).completeRestore(authHeader, completeRequest);
inOrder.verify(timeLockManagementService).reenableTimelock(authHeader, reenableRequest);
}
Aggregations