Search in sources :

Example 26 with AcknowledgedResponse

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

the class AlterTableOperation method executeAlterTableAddColumn.

public CompletableFuture<Long> executeAlterTableAddColumn(final BoundAddColumn analysis) {
    FutureActionListener<AcknowledgedResponse, Long> result = new FutureActionListener<>(r -> -1L);
    if (analysis.newPrimaryKeys() || analysis.hasNewGeneratedColumns()) {
        RelationName ident = analysis.table().ident();
        String stmt = String.format(Locale.ENGLISH, "SELECT COUNT(*) FROM \"%s\".\"%s\"", ident.schema(), ident.name());
        try {
            session().quickExec(stmt, new ResultSetReceiver(analysis, result), Row.EMPTY);
        } catch (Throwable t) {
            result.completeExceptionally(t);
        }
    } else {
        return addColumnToTable(analysis, result);
    }
    return result;
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RelationName(io.crate.metadata.RelationName) FutureActionListener(io.crate.action.FutureActionListener)

Example 27 with AcknowledgedResponse

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

the class TransportCreateTableAction method masterOperation.

@Override
protected void masterOperation(final CreateTableRequest request, final ClusterState state, final ActionListener<CreateTableResponse> listener) {
    final RelationName relationName = request.getTableName();
    if (viewsExists(relationName, state)) {
        listener.onFailure(new RelationAlreadyExists(relationName));
        return;
    }
    if (request.getCreateIndexRequest() != null) {
        CreateIndexRequest createIndexRequest = request.getCreateIndexRequest();
        ActionListener<CreateIndexResponse> wrappedListener = ActionListener.wrap(response -> listener.onResponse(new CreateTableResponse(response.isShardsAcknowledged())), listener::onFailure);
        transportCreateIndexAction.masterOperation(createIndexRequest, state, wrappedListener);
    } else if (request.getPutIndexTemplateRequest() != null) {
        PutIndexTemplateRequest putIndexTemplateRequest = request.getPutIndexTemplateRequest();
        ActionListener<AcknowledgedResponse> wrappedListener = ActionListener.wrap(response -> listener.onResponse(new CreateTableResponse(response.isAcknowledged())), listener::onFailure);
        transportPutIndexTemplateAction.masterOperation(putIndexTemplateRequest, state, wrappedListener);
    } else {
        throw new IllegalStateException("Unknown table request");
    }
}
Also used : RelationName(io.crate.metadata.RelationName) TransportPutIndexTemplateAction(org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction) ClusterService(org.elasticsearch.cluster.service.ClusterService) ViewsMetadata(io.crate.metadata.view.ViewsMetadata) IOException(java.io.IOException) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) Inject(org.elasticsearch.common.inject.Inject) TransportMasterNodeAction(org.elasticsearch.action.support.master.TransportMasterNodeAction) ClusterState(org.elasticsearch.cluster.ClusterState) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) TransportCreateIndexAction(org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ActionListener(org.elasticsearch.action.ActionListener) ActionListener(org.elasticsearch.action.ActionListener) RelationName(io.crate.metadata.RelationName) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) RelationAlreadyExists(io.crate.exceptions.RelationAlreadyExists) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 28 with AcknowledgedResponse

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

the class ShardingUpsertExecutor method createPartitions.

private CompletableFuture<AcknowledgedResponse> createPartitions(Map<String, List<ShardedRequests.ItemAndRoutingAndSourceInfo<ShardUpsertRequest.Item>>> itemsByMissingIndex) {
    FutureActionListener<AcknowledgedResponse, AcknowledgedResponse> listener = FutureActionListener.newInstance();
    createPartitionsAction.execute(new CreatePartitionsRequest(itemsByMissingIndex.keySet(), jobId), listener);
    return listener;
}
Also used : CreatePartitionsRequest(org.elasticsearch.action.admin.indices.create.CreatePartitionsRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse)

Example 29 with AcknowledgedResponse

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

the class InsertFromValues method createIndices.

private static CompletableFuture<AcknowledgedResponse> createIndices(TransportCreatePartitionsAction createPartitionsAction, Set<String> indices, ClusterService clusterService, UUID jobId) {
    Metadata metadata = clusterService.state().getMetadata();
    List<String> indicesToCreate = new ArrayList<>();
    for (var index : indices) {
        if (IndexParts.isPartitioned(index) && metadata.hasIndex(index) == false) {
            indicesToCreate.add(index);
        }
    }
    if (indicesToCreate.isEmpty()) {
        return CompletableFuture.completedFuture(new AcknowledgedResponse(true));
    }
    FutureActionListener<AcknowledgedResponse, AcknowledgedResponse> listener = new FutureActionListener<>(r -> r);
    createPartitionsAction.execute(new CreatePartitionsRequest(indicesToCreate, jobId), listener);
    return listener;
}
Also used : CreatePartitionsRequest(org.elasticsearch.action.admin.indices.create.CreatePartitionsRequest) Metadata(org.elasticsearch.cluster.metadata.Metadata) IntArrayList(com.carrotsearch.hppc.IntArrayList) ArrayList(java.util.ArrayList) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) FutureActionListener(io.crate.action.FutureActionListener)

Example 30 with AcknowledgedResponse

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

the class SysRepositoriesServiceTest method createRepository.

private void createRepository(String name) {
    AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository(name).setType("fs").setSettings(Settings.builder().put("location", new File(TEMP_FOLDER.getRoot(), "backup").getAbsolutePath()).put("chunk_size", "5k").put("compress", false)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    repositories.add(name);
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) File(java.io.File)

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