org.elasticsearch.action.support.master.AcknowledgedResponse Java Examples

The following examples show how to use org.elasticsearch.action.support.master.AcknowledgedResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlterTableOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<Long> executeAlterTableSetOrReset(BoundAlterTable analysis) {
    try {
        AlterTableRequest request = new AlterTableRequest(
            analysis.table().ident(),
            analysis.partitionName().map(PartitionName::asIndexName).orElse(null),
            analysis.isPartitioned(),
            analysis.excludePartitions(),
            analysis.tableParameter().settings(),
            analysis.tableParameter().mappings()
        );
        FutureActionListener<AcknowledgedResponse, Long> listener = new FutureActionListener<>(r -> -1L);
        transportAlterTableAction.execute(request, listener);
        return listener;
    } catch (IOException e) {
        return FutureActionListener.failedFuture(e);
    }
}
 
Example #2
Source File: SwapTablePlan.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {
    boolean dropSource = Objects.requireNonNull(DataTypes.BOOLEAN.value(SymbolEvaluator.evaluate(
        plannerContext.transactionContext(),
        dependencies.functions(),
        swapTable.dropSource(),
        params,
        subQueryResults
    )), SwapTableAnalyzer.DROP_SOURCE + " option must be true or false, not null");

    RelationName source = swapTable.source().ident();
    SwapRelationsRequest request = new SwapRelationsRequest(
        Collections.singletonList(new RelationNameSwap(source, swapTable.target().ident())),
        dropSource ? Collections.singletonList(source) : emptyList()
    );
    OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(
        consumer,
        r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L)
    );
    dependencies.swapRelationsAction().execute(request, listener);
}
 
Example #3
Source File: TransportDeleteIndexAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@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);
        }
    });
}
 
Example #4
Source File: AbstractElasticSearchIndexStrategy.java    From jetlinks-community with Apache License 2.0 6 votes vote down vote up
protected Mono<Void> doPutIndex(ElasticSearchIndexMetadata metadata,
                                boolean justUpdateMapping) {
    String index = wrapIndex(metadata.getIndex());
    return this.indexExists(index)
        .flatMap(exists -> {
            if (exists) {
                return doLoadIndexMetadata(index)
                    .flatMap(oldMapping -> Mono.justOrEmpty(createPutMappingRequest(metadata, oldMapping)))
                    .flatMap(request -> ReactorActionListener.<AcknowledgedResponse>mono(
                        actionListener ->
                            client.getWriteClient()
                                .indices()
                                .putMappingAsync(request, RequestOptions.DEFAULT, actionListener)))
                    .then();
            }
            if (justUpdateMapping) {
                return Mono.empty();
            }
            return doCreateIndex(metadata);
        });
}
 
Example #5
Source File: TransportOpenCloseTableOrPartitionAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Inject
public TransportOpenCloseTableOrPartitionAction(TransportService transportService,
                                                ClusterService clusterService,
                                                ThreadPool threadPool,
                                                IndexNameExpressionResolver indexNameExpressionResolver,
                                                AllocationService allocationService,
                                                DDLClusterStateService ddlClusterStateService,
                                                MetaDataIndexUpgradeService metaDataIndexUpgradeService,
                                                IndicesService indexServices) {
    super(ACTION_NAME,
        transportService,
        clusterService,
        threadPool,
        indexNameExpressionResolver,
        OpenCloseTableOrPartitionRequest::new,
        AcknowledgedResponse::new,
        AcknowledgedResponse::new,
        "open-table-or-partition");
    openExecutor = new OpenTableClusterStateTaskExecutor(indexNameExpressionResolver, allocationService,
        ddlClusterStateService, metaDataIndexUpgradeService, indexServices);
    closeExecutor = new CloseTableClusterStateTaskExecutor(indexNameExpressionResolver, allocationService,
        ddlClusterStateService);
}
 
Example #6
Source File: TransportSchemaUpdateAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(SchemaUpdateRequest request, ClusterState state, ActionListener<AcknowledgedResponse> listener) throws Exception {
    // ideally we'd handle the index mapping update together with the template update in a single clusterStateUpdateTask
    // but the index mapping-update logic is difficult to re-use
    if (IndexParts.isPartitioned(request.index().getName())) {
        updateTemplate(
            state.getMetaData().getTemplates(),
            request.index().getName(),
            request.mappingSource(),
            request.masterNodeTimeout()
        ).thenCompose(r -> updateMapping(request.index(), request.masterNodeTimeout(), request.mappingSource()))
            .thenApply(r -> new AcknowledgedResponse(r.isAcknowledged()))
            .whenComplete(ActionListener.toBiConsumer(listener));
    } else {
        updateMapping(request.index(), request.masterNodeTimeout(), request.mappingSource())
            .thenApply(r -> new AcknowledgedResponse(r.isAcknowledged()))
            .whenComplete(ActionListener.toBiConsumer(listener));
    }
}
 
Example #7
Source File: InsertFromValues.java    From crate with Apache License 2.0 6 votes vote down vote up
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);
        }
    }

    FutureActionListener<AcknowledgedResponse, AcknowledgedResponse> listener = new FutureActionListener<>(r -> r);
    createPartitionsAction.execute(new CreatePartitionsRequest(indicesToCreate, jobId), listener);
    return listener;
}
 
Example #8
Source File: TransportAnalyzeAction.java    From crate with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: TransportUpgradeSettingsAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(final UpgradeSettingsRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    UpgradeSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpgradeSettingsClusterStateUpdateRequest()
            .ackTimeout(request.timeout())
            .versions(request.versions())
            .masterNodeTimeout(request.masterNodeTimeout());

    updateSettingsService.upgradeIndexSettings(clusterStateUpdateRequest, 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 upgrade minimum compatibility version settings on indices [{}]", request.versions().keySet()), t);
            listener.onFailure(t);
        }
    });
}
 
Example #10
Source File: AlterTableOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
private CompletableFuture<Long> addColumnToTable(BoundAddColumn analysis, final FutureActionListener<AcknowledgedResponse, Long> result) {
    try {
        AlterTableRequest request = new AlterTableRequest(
            analysis.table().ident(),
            null,
            analysis.table().isPartitioned(),
            false,
            analysis.settings(),
            analysis.mapping()
        );
        transportAlterTableAction.execute(request, result);
        return result;
    } catch (IOException e) {
        return FutureActionListener.failedFuture(e);
    }
}
 
Example #11
Source File: ElasticSearchUtils.java    From ElasticUtils with MIT License 6 votes vote down vote up
private static AcknowledgedResponse internalPutMapping(Client client, String indexName, IElasticSearchMapping mapping) throws IOException {

        String json = Strings.toString(mapping.getMapping());

        final PutMappingRequest putMappingRequest = new PutMappingRequest(indexName)
                .type(mapping.getIndexType())
                .source(json, XContentType.JSON);

        final AcknowledgedResponse putMappingResponse = client
                .admin()
                .indices()
                .putMapping(putMappingRequest)
                .actionGet();

        if(log.isDebugEnabled()) {
            log.debug("PutMappingResponse: isAcknowledged {}", putMappingResponse.isAcknowledged());
        }

        return putMappingResponse;
    }
 
Example #12
Source File: AlterTableOperation.java    From crate with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #13
Source File: IndexUpdateMapping.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    PutMappingRequestBuilder request = elasticsearch.get().admin().indices()
            .preparePutMapping(index)
            .setSource(mapping)
            .setType(type);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }
    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(putMappingResponse -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(putMappingResponse)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #14
Source File: IndexCreate.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    CreateIndexRequestBuilder request = elasticsearch.get().admin().indices().prepareCreate(index);
    for (Map.Entry<String, String> entry : mappings.entrySet()) {
        String type = entry.getKey();
        String mapping = entry.getValue();
        request = request.addMapping(type, mapping);
    }
    if (settings != null) {
        request.setSettings(settings);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }

    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(createIndexResponse -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(createIndexResponse)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #15
Source File: IndexDelete.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    DeleteIndexRequestBuilder request = elasticsearch.get().admin().indices().prepareDelete(index);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }
    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(response -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(response)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #16
Source File: IndexUpdateSettings.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    UpdateSettingsRequestBuilder request = elasticsearch.get().admin().indices().prepareUpdateSettings(index);
    request.setSettings(settings);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }
    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(updateSettingsResponse -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(updateSettingsResponse)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #17
Source File: TransportUpdateSettingsAction.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest()
            .indices(concreteIndices)
            .settings(request.settings())
            .setPreserveExisting(request.isPreserveExisting())
            .ackTimeout(request.timeout())
            .masterNodeTimeout(request.masterNodeTimeout());

    updateSettingsService.updateSettings(clusterStateUpdateRequest, 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 update settings on indices [{}]", (Object) concreteIndices), t);
            listener.onFailure(t);
        }
    });
}
 
Example #18
Source File: DataServiceIndexTestsIT.java    From java-11-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void testDataServiceIndexCreateDelete() throws IOException {
    try {
        dataService.deleteIndex(INDEX_NAME);
    } catch (Exception e) {
    }

    Optional<CreateIndexResponse> createIndexResponse = dataService.createIndex(INDEX_NAME, Utils.createMapping());
    Assert.assertTrue(createIndexResponse.isPresent());
    Assert.assertTrue(createIndexResponse.get().isAcknowledged());

    Optional<Boolean> isCreated = dataService.isIndexCreated(INDEX_NAME);
    Assert.assertNotNull(isCreated.isPresent());
    Assert.assertTrue(isCreated.get());

    Optional<AcknowledgedResponse> deleteIndexResponse = dataService.deleteIndex(INDEX_NAME);
    Assert.assertTrue(deleteIndexResponse.isPresent());
    Assert.assertTrue(deleteIndexResponse.get().isAcknowledged());

    isCreated = dataService.isIndexCreated(INDEX_NAME);
    Assert.assertNotNull(isCreated.isPresent());
    Assert.assertFalse(isCreated.get());
}
 
Example #19
Source File: RestHighLevelClientCase.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void delete(RestHighLevelClient client, String indexName) throws IOException {
    DeleteIndexRequest request = new DeleteIndexRequest(indexName);
    AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT);
    if (!deleteIndexResponse.isAcknowledged()) {
        String message = "elasticsearch delete index fail.";
        logger.error(message);
        throw new RuntimeException(message);
    }
}
 
Example #20
Source File: TransportRenameTableAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(RenameTableRequest request, ClusterState state, ActionListener<AcknowledgedResponse> listener) throws Exception {
    AtomicReference<String[]> newIndexNames = new AtomicReference<>(null);
    ActionListener<AcknowledgedResponse> waitForShardsListener = ActionListeners.waitForShards(
        listener,
        activeShardsObserver,
        request.timeout(),
        () -> logger.info("Renamed a relation, but the operation timed out waiting for enough shards to become available"),
        newIndexNames::get
    );

    clusterService.submitStateUpdateTask(
        "rename-table",
        new AckedClusterStateUpdateTask<AcknowledgedResponse>(Priority.HIGH, request, waitForShardsListener) {
            @Override
            public ClusterState execute(ClusterState currentState) throws Exception {
                ClusterState updatedState = executor.execute(currentState, request);
                IndicesOptions openIndices = IndicesOptions.fromOptions(
                    true,
                    true,
                    true,
                    false,
                    true,
                    true,
                    false
                );
                newIndexNames.set(indexNameExpressionResolver.concreteIndexNames(
                        updatedState, openIndices, request.targetTableIdent().indexNameOrAlias()));
                return updatedState;
            }

            @Override
            protected AcknowledgedResponse newResponse(boolean acknowledged) {
                return new AcknowledgedResponse(acknowledged);
            }
        });
}
 
Example #21
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 5 votes vote down vote up
public AcknowledgedResponse closeIndex(final String index, final BuilderCallback<CloseIndexRequestBuilder> builder) {
    final AcknowledgedResponse actionGet = builder.apply(client().admin().indices().prepareClose(index)).execute().actionGet();
    if (!actionGet.isAcknowledged()) {
        onFailure("Failed to close " + index + ".", actionGet);
    }
    return actionGet;
}
 
Example #22
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 5 votes vote down vote up
public AcknowledgedResponse updateAlias(final String alias, final String[] addedIndices, final String[] deletedIndices) {
    return updateAlias(builder -> {
        if (addedIndices != null && addedIndices.length > 0) {
            builder.addAlias(addedIndices, alias);
        }
        if (deletedIndices != null && deletedIndices.length > 0) {
            builder.removeAlias(deletedIndices, alias);
        }
        return builder;
    });
}
 
Example #23
Source File: TransportDropUserDefinedFunctionAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(final DropUserDefinedFunctionRequest request,
                               ClusterState state,
                               ActionListener<AcknowledgedResponse> listener) throws Exception {
    udfService.dropFunction(
        request.schema(),
        request.name(),
        request.argumentTypes(),
        request.ifExists(),
        listener,
        request.masterNodeTimeout()
    );
}
 
Example #24
Source File: CaseController.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void delete(String indexName) throws IOException {
    DeleteIndexRequest request = new DeleteIndexRequest(indexName);
    AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT);
    if (!deleteIndexResponse.isAcknowledged()) {
        String message = "elasticsearch delete index fail.";
        logger.error(message);
        throw new RuntimeException(message);
    }
}
 
Example #25
Source File: TransportCreatePartitionsAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(final CreatePartitionsRequest request,
                               final ClusterState state,
                               final ActionListener<AcknowledgedResponse> listener) throws ElasticsearchException {

    if (request.indices().isEmpty()) {
        listener.onResponse(new AcknowledgedResponse(true));
        return;
    }

    createIndices(request, ActionListener.wrap(response -> {
        if (response.isAcknowledged()) {
            activeShardsObserver.waitForActiveShards(request.indices().toArray(new String[0]), ActiveShardCount.DEFAULT, request.ackTimeout(),
                shardsAcked -> {
                    if (!shardsAcked && logger.isInfoEnabled()) {
                        String partitionTemplateName = PartitionName.templateName(request.indices().iterator().next());
                        IndexTemplateMetaData templateMetaData = state.metaData().getTemplates().get(partitionTemplateName);

                        logger.info("[{}] Table partitions created, but the operation timed out while waiting for " +
                                     "enough shards to be started. Timeout={}, wait_for_active_shards={}. " +
                                     "Consider decreasing the 'number_of_shards' table setting (currently: {}) or adding nodes to the cluster.",
                            request.indices(), request.timeout(),
                            SETTING_WAIT_FOR_ACTIVE_SHARDS.get(templateMetaData.getSettings()),
                            INDEX_NUMBER_OF_SHARDS_SETTING.get(templateMetaData.getSettings()));
                    }
                    listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
                }, listener::onFailure);
        } else {
            logger.warn("[{}] Table partitions created, but publishing new cluster state timed out. Timeout={}",
                request.indices(), request.timeout());
            listener.onResponse(new AcknowledgedResponse(false));
        }
    }, listener::onFailure));
}
 
Example #26
Source File: TransportCreateUserDefinedFunctionAction.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(final CreateUserDefinedFunctionRequest request,
                               ClusterState state,
                               ActionListener<AcknowledgedResponse> listener) throws Exception {
    UserDefinedFunctionMetaData metaData = request.userDefinedFunctionMetaData();
    String errorMessage = udfService.getLanguage(metaData.language()).validate(metaData);
    if (errorMessage != null) {
        throw new ScriptException(errorMessage, metaData.language());
    }
    udfService.registerFunction(metaData, request.replace(), listener, request.masterNodeTimeout());
}
 
Example #27
Source File: DropFunctionPlan.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params, SubQueryResults subQueryResults) throws Exception {
    DropUserDefinedFunctionRequest request = new DropUserDefinedFunctionRequest(
        analyzedDropFunction.schema(),
        analyzedDropFunction.name(),
        analyzedDropFunction.argumentTypes(),
        analyzedDropFunction.ifExists()
    );
    OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(consumer, r -> new Row1(1L));
    dependencies.dropFunctionAction().execute(request, listener);
}
 
Example #28
Source File: ActionListeners.java    From crate with Apache License 2.0 5 votes vote down vote up
public static <T extends AcknowledgedResponse> ActionListener<T> waitForShards(ActionListener<T> delegate,
                                                                               ActiveShardsObserver observer,
                                                                               TimeValue timeout,
                                                                               Runnable onShardsNotAcknowledged,
                                                                               Supplier<String[]> indices) {

    return ActionListener.wrap(
        resp -> {
            if (resp.isAcknowledged()) {
                observer.waitForActiveShards(
                    indices.get(),
                    ActiveShardCount.DEFAULT,
                    timeout,
                    shardsAcknowledged -> {
                        if (!shardsAcknowledged) {
                            onShardsNotAcknowledged.run();
                        }
                        delegate.onResponse(resp);
                    },
                    delegate::onFailure
                );
            } else {
                delegate.onResponse(resp);
            }
        },
        delegate::onFailure
    );
}
 
Example #29
Source File: ElasticsearchClusterRunner.java    From elasticsearch-cluster-runner with Apache License 2.0 5 votes vote down vote up
public AcknowledgedResponse createMapping(final String index, final BuilderCallback<PutMappingRequestBuilder> builder) {
    final AcknowledgedResponse actionGet = builder.apply(client().admin().indices().preparePutMapping(index)).execute().actionGet();
    if (!actionGet.isAcknowledged()) {
        onFailure("Failed to create a mapping for " + index + ".", actionGet);
    }
    return actionGet;
}
 
Example #30
Source File: AlterTableOperation.java    From crate with Apache License 2.0 5 votes vote down vote up
private CompletableFuture<Long> deleteIndex(String... indexNames) {
    DeleteIndexRequest request = new DeleteIndexRequest(indexNames);

    FutureActionListener<AcknowledgedResponse, Long> listener = new FutureActionListener<>(r -> 0L);
    transportDeleteIndexAction.execute(request, listener);
    return listener;
}