use of io.crate.action.FutureActionListener in project crate by crate.
the class TransportFetchOperation method fetch.
@Override
public CompletableFuture<IntObjectMap<? extends Bucket>> fetch(String nodeId, IntObjectMap<? extends IntContainer> toFetch, boolean closeContext) {
FutureActionListener<NodeFetchResponse, IntObjectMap<? extends Bucket>> listener = new FutureActionListener<>(GET_FETCHED);
transportFetchNodeAction.execute(nodeId, nodeIdToReaderIdToStreamers.get(nodeId), new NodeFetchRequest(jobId, executionPhaseId, closeContext, toFetch), listener);
return listener;
}
use of io.crate.action.FutureActionListener in project crate by crate.
the class SnapshotRestoreDDLDispatcher method dispatch.
public CompletableFuture<Long> dispatch(final RestoreSnapshotAnalyzedStatement analysis) {
boolean waitForCompletion = analysis.settings().getAsBoolean(WAIT_FOR_COMPLETION.settingName(), WAIT_FOR_COMPLETION.defaultValue());
boolean ignoreUnavailable = analysis.settings().getAsBoolean(IGNORE_UNAVAILABLE.settingName(), IGNORE_UNAVAILABLE.defaultValue());
// ignore_unavailable as set by statement
IndicesOptions indicesOptions = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, IndicesOptions.lenientExpandOpen());
FutureActionListener<RestoreSnapshotResponse, Long> listener = new FutureActionListener<>(Functions.constant(1L));
resolveIndexNames(analysis.restoreTables(), ignoreUnavailable, transportActionProvider.transportGetSnapshotsAction(), analysis.repositoryName()).whenComplete((List<String> indexNames, Throwable t) -> {
if (t == null) {
RestoreSnapshotRequest request = new RestoreSnapshotRequest(analysis.repositoryName(), analysis.snapshotName()).indices(indexNames).indicesOptions(indicesOptions).settings(analysis.settings()).waitForCompletion(waitForCompletion).includeGlobalState(false).includeAliases(true);
transportActionProvider.transportRestoreSnapshotAction().execute(request, listener);
} else {
listener.onFailure(t);
}
});
return listener;
}
use of io.crate.action.FutureActionListener in project crate by crate.
the class AlterTableOperation method updateTemplate.
private CompletableFuture<Long> updateTemplate(Map<String, Object> newMappings, Settings newSettings, TableIdent tableIdent) {
String templateName = PartitionName.templateName(tableIdent.schema(), tableIdent.name());
IndexTemplateMetaData indexTemplateMetaData = clusterService.state().metaData().templates().get(templateName);
if (indexTemplateMetaData == null) {
return CompletableFutures.failedFuture(new RuntimeException("Template for partitioned table is missing"));
}
// merge mappings
Map<String, Object> mapping = mergeTemplateMapping(indexTemplateMetaData, newMappings);
// merge settings
Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put(indexTemplateMetaData.settings());
settingsBuilder.put(newSettings);
PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).create(false).mapping(Constants.DEFAULT_MAPPING_TYPE, mapping).order(indexTemplateMetaData.order()).settings(settingsBuilder.build()).template(indexTemplateMetaData.template());
for (ObjectObjectCursor<String, AliasMetaData> container : indexTemplateMetaData.aliases()) {
Alias alias = new Alias(container.key);
request.alias(alias);
}
FutureActionListener<PutIndexTemplateResponse, Long> listener = new FutureActionListener<>(LONG_NULL_FUNCTION);
transportActionProvider.transportPutIndexTemplateAction().execute(request, listener);
return listener;
}
use of io.crate.action.FutureActionListener in project crate by crate.
the class AlterTableOperation method updateMapping.
private CompletableFuture<Long> updateMapping(Map<String, Object> newMapping, String... indices) {
if (newMapping.isEmpty()) {
return CompletableFuture.completedFuture(null);
}
assert areAllMappingsEqual(clusterService.state().metaData(), indices) : "Trying to update mapping for indices with different existing mappings";
Map<String, Object> mapping;
try {
MetaData metaData = clusterService.state().metaData();
String index = indices[0];
mapping = metaData.index(index).mapping(Constants.DEFAULT_MAPPING_TYPE).getSourceAsMap();
} catch (IOException e) {
return CompletableFutures.failedFuture(e);
}
XContentHelper.update(mapping, newMapping, false);
// update mapping of all indices
PutMappingRequest request = new PutMappingRequest(indices);
request.indicesOptions(IndicesOptions.lenientExpandOpen());
request.type(Constants.DEFAULT_MAPPING_TYPE);
request.source(mapping);
FutureActionListener<PutMappingResponse, Long> listener = new FutureActionListener<>(LONG_NULL_FUNCTION);
transportActionProvider.transportPutMappingAction().execute(request, listener);
return listener;
}
Aggregations