Search in sources :

Example 6 with FutureActionListener

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;
}
Also used : NodeFetchRequest(io.crate.executor.transport.NodeFetchRequest) IntObjectMap(com.carrotsearch.hppc.IntObjectMap) Bucket(io.crate.data.Bucket) FutureActionListener(io.crate.action.FutureActionListener) NodeFetchResponse(io.crate.executor.transport.NodeFetchResponse)

Example 7 with FutureActionListener

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;
}
Also used : RestoreSnapshotRequest(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) FutureActionListener(io.crate.action.FutureActionListener) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 8 with FutureActionListener

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;
}
Also used : PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) FutureActionListener(io.crate.action.FutureActionListener) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) Alias(org.elasticsearch.action.admin.indices.alias.Alias) PutIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse) Settings(org.elasticsearch.common.settings.Settings)

Example 9 with FutureActionListener

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;
}
Also used : PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) MetaData(org.elasticsearch.cluster.metadata.MetaData) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) IOException(java.io.IOException) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) FutureActionListener(io.crate.action.FutureActionListener)

Aggregations

FutureActionListener (io.crate.action.FutureActionListener)9 UpdateSettingsRequest (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest)2 UpdateSettingsResponse (org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse)2 AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)2 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)2 IntObjectMap (com.carrotsearch.hppc.IntObjectMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Bucket (io.crate.data.Bucket)1 NodeFetchRequest (io.crate.executor.transport.NodeFetchRequest)1 NodeFetchResponse (io.crate.executor.transport.NodeFetchResponse)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 RestoreSnapshotRequest (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)1 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)1 Alias (org.elasticsearch.action.admin.indices.alias.Alias)1 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)1 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)1 ForceMergeRequest (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest)1 ForceMergeResponse (org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse)1