use of io.crate.exceptions.CreateSnapshotException in project crate by crate.
the class SnapshotRestoreDDLDispatcher method dispatch.
public CompletableFuture<Long> dispatch(final CreateSnapshotAnalyzedStatement statement) {
final CompletableFuture<Long> resultFuture = new CompletableFuture<>();
boolean waitForCompletion = statement.snapshotSettings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
boolean ignoreUnavailable = statement.snapshotSettings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
CreateSnapshotRequest request = new CreateSnapshotRequest(statement.snapshotId().getRepository(), statement.snapshotId().getSnapshot()).includeGlobalState(statement.includeMetadata()).waitForCompletion(waitForCompletion).indices(statement.indices()).indicesOptions(indicesOptions).settings(statement.snapshotSettings());
//noinspection ThrowableResultOfMethodCallIgnored
assert request.validate() == null : "invalid CREATE SNAPSHOT statement";
transportActionProvider.transportCreateSnapshotAction().execute(request, new ActionListener<CreateSnapshotResponse>() {
@Override
public void onResponse(CreateSnapshotResponse createSnapshotResponse) {
SnapshotInfo snapshotInfo = createSnapshotResponse.getSnapshotInfo();
if (snapshotInfo == null) {
// if wait_for_completion is false the snapshotInfo is null
resultFuture.complete(1L);
} else if (snapshotInfo.state() == SnapshotState.FAILED) {
// fail request if snapshot creation failed
String reason = createSnapshotResponse.getSnapshotInfo().reason().replaceAll("Index", "Table").replaceAll("Indices", "Tables");
resultFuture.completeExceptionally(new CreateSnapshotException(statement.snapshotId(), reason));
} else {
resultFuture.complete(1L);
}
}
@Override
public void onFailure(Throwable e) {
resultFuture.completeExceptionally(e);
}
});
return resultFuture;
}
Aggregations