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