Search in sources :

Example 1 with UnsuccessfulDisableNamespacesResponse

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

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 AtlasService (com.palantir.atlasdb.backup.api.AtlasService)1 CompleteRestoreRequest (com.palantir.atlasdb.backup.api.CompleteRestoreRequest)1 CompletedBackup (com.palantir.atlasdb.backup.api.CompletedBackup)1 DisableNamespacesRequest (com.palantir.atlasdb.timelock.api.DisableNamespacesRequest)1 DisableNamespacesResponse (com.palantir.atlasdb.timelock.api.DisableNamespacesResponse)1 Namespace (com.palantir.atlasdb.timelock.api.Namespace)1 SuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.SuccessfulDisableNamespacesResponse)1 UnsuccessfulDisableNamespacesResponse (com.palantir.atlasdb.timelock.api.UnsuccessfulDisableNamespacesResponse)1 SafeIllegalStateException (com.palantir.logsafe.exceptions.SafeIllegalStateException)1 Set (java.util.Set)1