Search in sources :

Example 1 with DisableNamespacesRequest

use of com.palantir.atlasdb.timelock.api.DisableNamespacesRequest in project atlasdb by palantir.

the class AtlasRestoreServiceTest method prepareBackupFailsIfDisableFails.

@Test
public void prepareBackupFailsIfDisableFails() {
    DisableNamespacesResponse failedDisable = DisableNamespacesResponse.unsuccessful(UnsuccessfulDisableNamespacesResponse.of(ImmutableSet.of(WITH_BACKUP), ImmutableSet.of()));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(failedDisable);
    Set<Namespace> disabledNamespaces = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest(WITH_BACKUP), restoreRequest(NO_BACKUP)), BACKUP_ID);
    assertThat(disabledNamespaces).isEmpty();
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 2 with DisableNamespacesRequest

use of com.palantir.atlasdb.timelock.api.DisableNamespacesRequest 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);
}
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) 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) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) Optional(java.util.Optional) 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) 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) Namespace(com.palantir.atlasdb.timelock.api.Namespace) Test(org.junit.Test)

Example 3 with DisableNamespacesRequest

use of com.palantir.atlasdb.timelock.api.DisableNamespacesRequest in project atlasdb by palantir.

the class AtlasRestoreService method prepareRestore.

/**
 * Disables TimeLock on all nodes for the given atlasServices.
 * This will fail if any atlasService is already disabled, unless it was disabled with the provided backupId.
 * AtlasServices for which we don't have a recorded backup will be ignored.
 *
 * @param restoreRequests the requests to prepare.
 * @param backupId a unique identifier for this request (uniquely identifies the backup to which we're restoring)
 *
 * @return the atlasServices successfully disabled.
 */
public Set<AtlasService> prepareRestore(Set<RestoreRequest> restoreRequests, String backupId) {
    validateRestoreRequests(restoreRequests);
    Map<RestoreRequest, CompletedBackup> completedBackups = getCompletedBackups(restoreRequests);
    Set<AtlasService> atlasServicesToRestore = getAtlasServicesToRestore(completedBackups);
    Preconditions.checkArgument(atlasServicesToRestore.size() == completedBackups.size(), "Attempting to restore multiple atlasServices into the same atlasService! " + "This will cause severe data corruption.", SafeArg.of("restoreRequests", restoreRequests));
    Set<Namespace> namespacesToRestore = atlasServicesToRestore.stream().map(AtlasService::getNamespace).collect(Collectors.toSet());
    DisableNamespacesRequest request = DisableNamespacesRequest.of(namespacesToRestore, backupId);
    DisableNamespacesResponse response = timeLockManagementService.disableTimelock(authHeader, request);
    return response.accept(new DisableNamespacesResponse.Visitor<>() {

        @Override
        public Set<AtlasService> visitSuccessful(SuccessfulDisableNamespacesResponse value) {
            return atlasServicesToRestore;
        }

        @Override
        public Set<AtlasService> visitUnsuccessful(UnsuccessfulDisableNamespacesResponse value) {
            log.error("Failed to disable namespaces prior to restore", SafeArg.of("requests", restoreRequests), SafeArg.of("response", value));
            return ImmutableSet.of();
        }

        @Override
        public Set<AtlasService> visitUnknown(String unknownType) {
            throw new SafeIllegalStateException("Unknown DisableNamespacesResponse", SafeArg.of("unknownType", unknownType));
        }
    });
}
Also used : AtlasService(com.palantir.atlasdb.backup.api.AtlasService) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Namespace(com.palantir.atlasdb.timelock.api.Namespace) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) CompletedBackup(com.palantir.atlasdb.backup.api.CompletedBackup) CompleteRestoreRequest(com.palantir.atlasdb.backup.api.CompleteRestoreRequest) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)

Example 4 with DisableNamespacesRequest

use of com.palantir.atlasdb.timelock.api.DisableNamespacesRequest in project atlasdb by palantir.

the class AtlasRestoreServiceTest method prepareReturnsOnlyCompletedBackups.

@Test
public void prepareReturnsOnlyCompletedBackups() {
    DisableNamespacesResponse successfulDisable = DisableNamespacesResponse.successful(SuccessfulDisableNamespacesResponse.of(BACKUP_ID));
    DisableNamespacesRequest request = DisableNamespacesRequest.of(ImmutableSet.of(WITH_BACKUP_NS), BACKUP_ID);
    when(timeLockManagementService.disableTimelock(authHeader, request)).thenReturn(successfulDisable);
    Set<AtlasService> disabledAtlasServices = atlasRestoreService.prepareRestore(ImmutableSet.of(restoreRequest(WITH_BACKUP), restoreRequest(NO_BACKUP)), BACKUP_ID);
    assertThat(disabledAtlasServices).containsExactly(WITH_BACKUP);
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) AtlasService(com.palantir.atlasdb.backup.api.AtlasService) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Test(org.junit.Test)

Example 5 with DisableNamespacesRequest

use of com.palantir.atlasdb.timelock.api.DisableNamespacesRequest in project atlasdb by palantir.

the class AllNodesDisabledNamespacesUpdaterTest method canDisableSingleNamespace.

@Test
public void canDisableSingleNamespace() {
    when(remote1.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(remote2.disable(any(), any())).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    when(localUpdater.disable(any(DisableNamespacesRequest.class))).thenReturn(SUCCESSFUL_SINGLE_NODE_UPDATE);
    DisableNamespacesResponse response = updater.disableOnAllNodes(AUTH_HEADER, disableNamespacesRequest(ImmutableSet.of(NAMESPACE)));
    assertThat(response).isEqualTo(successfulDisableResponse());
}
Also used : SuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse) UnsuccessfulDisableNamespacesResponse(com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse) DisableNamespacesResponse(com.palantir.atlasdb.timelock.api.DisableNamespacesResponse) DisableNamespacesRequest(com.palantir.atlasdb.timelock.api.DisableNamespacesRequest) Test(org.junit.Test)

Aggregations

DisableNamespacesRequest (com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)8 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)7 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)7 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)7 Test (org.junit.Test)7 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)4 Namespace (com.palantir.atlasdb.timelock.api.Namespace)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 CompleteRestoreRequest (com.palantir.atlasdb.backup.api.CompleteRestoreRequest)3 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)3 Set (java.util.Set)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AtlasRestoreClient (com.palantir.atlasdb.backup.api.AtlasRestoreClient)2 CompleteRestoreResponse (com.palantir.atlasdb.backup.api.CompleteRestoreResponse)2 CassandraRepairHelper (com.palantir.atlasdb.cassandra.backup.CassandraRepairHelper)2 RangesForRepair (com.palantir.atlasdb.cassandra.backup.RangesForRepair)2 ReenableNamespacesRequest (com.palantir.atlasdb.timelock.api.ReenableNamespacesRequest)2 TimeLockManagementService (com.palantir.atlasdb.timelock.api.management.TimeLockManagementService)2 KeyedStream (com.palantir.common.streams.KeyedStream)2 SafeIllegalArgumentException (com.palantir.logsafe.exceptions.SafeIllegalArgumentException)2