Search in sources :

Example 31 with AcknowledgedResponse

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

the class SysRepositoriesServiceTest method deleteRepository.

private void deleteRepository(String name) {
    AcknowledgedResponse deleteRepositoryResponse = client().admin().cluster().prepareDeleteRepository(name).get();
    assertThat(deleteRepositoryResponse.isAcknowledged(), equalTo(true));
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse)

Example 32 with AcknowledgedResponse

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

the class CreateFunctionPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) throws Exception {
    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(plannerContext.transactionContext(), plannerContext.nodeContext(), x, params, subQueryResults);
    UserDefinedFunctionMetadata metadata = new UserDefinedFunctionMetadata(createFunction.schema(), createFunction.name(), createFunction.arguments(), createFunction.returnType(), StringType.INSTANCE.sanitizeValue(eval.apply(createFunction.language())), StringType.INSTANCE.sanitizeValue(eval.apply(createFunction.definition())));
    CreateUserDefinedFunctionRequest request = new CreateUserDefinedFunctionRequest(metadata, createFunction.replace());
    OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(consumer, r -> new Row1(1L));
    dependencies.createFunctionAction().execute(request, listener);
}
Also used : CreateUserDefinedFunctionRequest(io.crate.expression.udf.CreateUserDefinedFunctionRequest) StringType(io.crate.types.StringType) AnalyzedCreateFunction(io.crate.analyze.AnalyzedCreateFunction) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Function(java.util.function.Function) RowConsumer(io.crate.data.RowConsumer) DependencyCarrier(io.crate.planner.DependencyCarrier) UserDefinedFunctionMetadata(io.crate.expression.udf.UserDefinedFunctionMetadata) SymbolEvaluator(io.crate.analyze.SymbolEvaluator) Row(io.crate.data.Row) Symbol(io.crate.expression.symbol.Symbol) PlannerContext(io.crate.planner.PlannerContext) Plan(io.crate.planner.Plan) SubQueryResults(io.crate.planner.operators.SubQueryResults) OneRowActionListener(io.crate.execution.support.OneRowActionListener) Row1(io.crate.data.Row1) Row1(io.crate.data.Row1) OneRowActionListener(io.crate.execution.support.OneRowActionListener) UserDefinedFunctionMetadata(io.crate.expression.udf.UserDefinedFunctionMetadata) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) CreateUserDefinedFunctionRequest(io.crate.expression.udf.CreateUserDefinedFunctionRequest)

Example 33 with AcknowledgedResponse

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

the class DropTablePlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    TableInfo table = dropTable.table();
    DropTableRequest request;
    if (table == null) {
        if (dropTable.maybeCorrupt()) {
            // setting isPartitioned=true should be safe.
            // It will delete a template if it exists, and if there is no template it shouldn't do any harm
            request = new DropTableRequest(dropTable.tableName(), true);
        } else {
            // no-op, table is already gone
            assert dropTable.dropIfExists() : "If table is null, IF EXISTS flag must have been present";
            consumer.accept(InMemoryBatchIterator.of(ROW_ZERO, SENTINEL), null);
            return;
        }
    } else {
        boolean isPartitioned = table instanceof DocTableInfo && ((DocTableInfo) table).isPartitioned();
        request = new DropTableRequest(table.ident(), isPartitioned);
    }
    dependencies.transportDropTableAction().execute(request, new ActionListener<>() {

        @Override
        public void onResponse(AcknowledgedResponse response) {
            if (!response.isAcknowledged() && LOGGER.isWarnEnabled()) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Dropping table {} was not acknowledged. This could lead to inconsistent state.", dropTable.tableName());
                }
            }
            consumer.accept(InMemoryBatchIterator.of(ROW_ONE, SENTINEL), null);
        }

        @Override
        public void onFailure(Exception e) {
            if (dropTable.dropIfExists() && e instanceof IndexNotFoundException) {
                consumer.accept(InMemoryBatchIterator.of(ROW_ZERO, SENTINEL), null);
            } else {
                consumer.accept(null, e);
            }
        }
    });
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) DocTableInfo(io.crate.metadata.doc.DocTableInfo) TableInfo(io.crate.metadata.table.TableInfo) DropTableRequest(io.crate.execution.ddl.tables.DropTableRequest) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 34 with AcknowledgedResponse

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

the class GCDangingArtifactsPlan method executeOrFail.

@Override
public void executeOrFail(DependencyCarrier dependencies, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
    OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(consumer, r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L));
    dependencies.transportActionProvider().transportDeleteIndexAction().execute(new DeleteIndexRequest(IndexParts.DANGLING_INDICES_PREFIX_PATTERNS.toArray(new String[0])), listener);
}
Also used : Row1(io.crate.data.Row1) OneRowActionListener(io.crate.execution.support.OneRowActionListener) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)

Example 35 with AcknowledgedResponse

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

the class TransportDeleteIndexAction method masterOperation.

@Override
protected void masterOperation(final DeleteIndexRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    final Set<Index> concreteIndices = new HashSet<>(Arrays.asList(indexNameExpressionResolver.concreteIndices(state, request)));
    if (concreteIndices.isEmpty()) {
        listener.onResponse(new AcknowledgedResponse(true));
        return;
    }
    DeleteIndexClusterStateUpdateRequest deleteRequest = new DeleteIndexClusterStateUpdateRequest().ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout()).indices(concreteIndices.toArray(new Index[concreteIndices.size()]));
    deleteIndexService.deleteIndices(deleteRequest, new ActionListener<ClusterStateUpdateResponse>() {

        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug(() -> new ParameterizedMessage("failed to delete indices [{}]", concreteIndices), t);
            listener.onFailure(t);
        }
    });
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Index(org.elasticsearch.index.Index) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) IOException(java.io.IOException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) HashSet(java.util.HashSet)

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