Search in sources :

Example 11 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class TransportAnalyzeAction method publishTableStats.

private CompletableFuture<AcknowledgedResponse> publishTableStats(Map<RelationName, Stats> newTableStats) {
    List<DiscoveryNode> nodesOn41OrAfter = StreamSupport.stream(clusterService.state().nodes().spliterator(), false).filter(x -> x.getVersion().onOrAfter(Version.V_4_1_0)).collect(Collectors.toList());
    var listener = new FutureActionListener<AcknowledgedResponse, AcknowledgedResponse>(x -> x);
    var multiListener = new MultiActionListener<>(nodesOn41OrAfter.size(), Collectors.reducing(new AcknowledgedResponse(true), (resp1, resp2) -> new AcknowledgedResponse(resp1.isAcknowledged() && resp2.isAcknowledged())), listener);
    var responseHandler = new ActionListenerResponseHandler<>(multiListener, AcknowledgedResponse::new, ThreadPool.Names.SAME);
    PublishTableStatsRequest request = new PublishTableStatsRequest(newTableStats);
    for (DiscoveryNode node : nodesOn41OrAfter) {
        transportService.sendRequest(node, RECEIVE_TABLE_STATS, request, responseHandler);
    }
    return listener;
}
Also used : Arrays(java.util.Arrays) RelationName(io.crate.metadata.RelationName) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) Symbols(io.crate.expression.symbol.Symbols) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) FutureActionListener(io.crate.action.FutureActionListener) SchemaInfo(io.crate.metadata.table.SchemaInfo) TableInfo(io.crate.metadata.table.TableInfo) Streamer(io.crate.Streamer) NodeActionRequestHandler(io.crate.execution.support.NodeActionRequestHandler) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) CompletableFutures(io.crate.concurrent.CompletableFutures) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Collectors(java.util.stream.Collectors) MultiActionListener(io.crate.execution.support.MultiActionListener) List(java.util.List) Version(org.elasticsearch.Version) Row(io.crate.data.Row) AnalyzeRequest(io.crate.execution.ddl.AnalyzeRequest) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MultiActionListener(io.crate.execution.support.MultiActionListener) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) FutureActionListener(io.crate.action.FutureActionListener)

Example 12 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class TransportAnalyzeAction method fetchSamplesThenGenerateAndPublishStats.

@SuppressWarnings("unchecked")
public CompletableFuture<AcknowledgedResponse> fetchSamplesThenGenerateAndPublishStats() {
    ArrayList<CompletableFuture<Map.Entry<RelationName, Stats>>> futures = new ArrayList<>();
    for (SchemaInfo schema : schemas) {
        if (!(schema instanceof DocSchemaInfo)) {
            continue;
        }
        for (TableInfo table : schema.getTables()) {
            List<Reference> primitiveColumns = StreamSupport.stream(table.spliterator(), false).filter(x -> !x.column().isSystemColumn()).filter(x -> DataTypes.isPrimitive(x.valueType())).map(x -> table.getReadReference(x.column())).collect(Collectors.toList());
            futures.add(fetchSamples(table.ident(), primitiveColumns).thenApply(samples -> Map.entry(table.ident(), createTableStats(samples, primitiveColumns))));
        }
    }
    return CompletableFutures.allAsList(futures).thenCompose(entries -> publishTableStats(Map.ofEntries(entries.toArray(new Map.Entry[0]))));
}
Also used : Arrays(java.util.Arrays) RelationName(io.crate.metadata.RelationName) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ClusterService(org.elasticsearch.cluster.service.ClusterService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ActionListenerResponseHandler(org.elasticsearch.action.ActionListenerResponseHandler) Symbols(io.crate.expression.symbol.Symbols) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) StreamSupport(java.util.stream.StreamSupport) TransportService(org.elasticsearch.transport.TransportService) FutureActionListener(io.crate.action.FutureActionListener) SchemaInfo(io.crate.metadata.table.SchemaInfo) TableInfo(io.crate.metadata.table.TableInfo) Streamer(io.crate.Streamer) NodeActionRequestHandler(io.crate.execution.support.NodeActionRequestHandler) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType) CompletableFutures(io.crate.concurrent.CompletableFutures) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Collectors(java.util.stream.Collectors) MultiActionListener(io.crate.execution.support.MultiActionListener) List(java.util.List) Version(org.elasticsearch.Version) Row(io.crate.data.Row) AnalyzeRequest(io.crate.execution.ddl.AnalyzeRequest) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) DataTypes(io.crate.types.DataTypes) Singleton(org.elasticsearch.common.inject.Singleton) Schemas(io.crate.metadata.Schemas) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) Reference(io.crate.metadata.Reference) ArrayList(java.util.ArrayList) CompletableFuture(java.util.concurrent.CompletableFuture) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo) RelationName(io.crate.metadata.RelationName) TableInfo(io.crate.metadata.table.TableInfo) HashMap(java.util.HashMap) Map(java.util.Map) SchemaInfo(io.crate.metadata.table.SchemaInfo) DocSchemaInfo(io.crate.metadata.doc.DocSchemaInfo)

Example 13 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class TransportCreatePartitionsActionTest method testCreateBulkIndicesSimple.

@Test
public void testCreateBulkIndicesSimple() throws Exception {
    List<String> indices = Arrays.asList("index1", "index2", "index3", "index4");
    AcknowledgedResponse response = action.execute(new CreatePartitionsRequest(indices, UUID.randomUUID())).get();
    assertThat(response.isAcknowledged(), is(true));
    Metadata indexMetadata = internalCluster().clusterService().state().metadata();
    for (String index : indices) {
        assertThat(indexMetadata.hasIndex(index), is(true));
    }
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Metadata(org.elasticsearch.cluster.metadata.Metadata) Test(org.junit.Test)

Example 14 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class TransportCreatePartitionsActionTest method testEmpty.

@Test
public void testEmpty() throws Exception {
    AcknowledgedResponse response = action.execute(new CreatePartitionsRequest(List.of(), UUID.randomUUID())).get();
    assertThat(response.isAcknowledged(), is(true));
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Test(org.junit.Test)

Example 15 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method deleteIndexTemplate.

@Override
public boolean deleteIndexTemplate(String templateName) {
    final DeleteIndexTemplateRequest request = new DeleteIndexTemplateRequest(templateName);
    final AcknowledgedResponse result = client.execute((c, requestOptions) -> c.indices().deleteTemplate(request, requestOptions), "Unable to delete index template " + templateName);
    return result.isAcknowledged();
}
Also used : AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) DeleteIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)

Aggregations

AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)37 IOException (java.io.IOException)11 FutureActionListener (io.crate.action.FutureActionListener)9 ClusterState (org.elasticsearch.cluster.ClusterState)7 Row1 (io.crate.data.Row1)6 Map (java.util.Map)6 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)6 Metadata (org.elasticsearch.cluster.metadata.Metadata)6 Row (io.crate.data.Row)5 RelationName (io.crate.metadata.RelationName)5 Arrays (java.util.Arrays)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Reference (io.crate.metadata.Reference)4 DataType (io.crate.types.DataType)4 ArrayList (java.util.ArrayList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 StreamSupport (java.util.stream.StreamSupport)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4