Java Code Examples for org.elasticsearch.action.ActionListener#onResponse()
The following examples show how to use
org.elasticsearch.action.ActionListener#onResponse() .
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: TransportUpgradeAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void doExecute(Task task, UpgradeRequest request, final ActionListener<UpgradeResponse> listener) { ActionListener<UpgradeResponse> settingsUpdateListener = new ActionListener<UpgradeResponse>() { @Override public void onResponse(UpgradeResponse upgradeResponse) { try { if (upgradeResponse.versions().isEmpty()) { listener.onResponse(upgradeResponse); } else { updateSettings(upgradeResponse, listener); } } catch (Throwable t) { listener.onFailure(t); } } @Override public void onFailure(Throwable e) { listener.onFailure(e); } }; super.doExecute(task, request, settingsUpdateListener); }
Example 2
Source File: FeatureManager.java From anomaly-detection with Apache License 2.0 | 6 votes |
private void getProcessedFeatures( Deque<Entry<Long, double[]>> shingle, AnomalyDetector detector, long endTime, ActionListener<SinglePointFeatures> listener ) { double[][] currentPoints = filterAndFill(shingle, endTime, detector); Optional<double[]> currentPoint = Optional.ofNullable(shingle.peekLast()).map(Entry::getValue); listener .onResponse( Optional .ofNullable(currentPoints) .map(points -> new SinglePointFeatures(currentPoint, Optional.of(batchShingle(points, shingleSize)[0]))) .orElse(new SinglePointFeatures(currentPoint, Optional.empty())) ); }
Example 3
Source File: TransportDeleteIndexAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void masterOperation(final DeleteIndexRequest request, final ClusterState state, final ActionListener<DeleteIndexResponse> listener) { final String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); if (concreteIndices.length == 0) { listener.onResponse(new DeleteIndexResponse(true)); return; } // add tenantid to index metadata LoginUserContext userInfo = (LoginUserContext)request.getHeader(LoginUserContext.USER_INFO_KEY); deleteIndexService.deleteIndices(new MetaDataDeleteIndexService.Request(concreteIndices, userInfo).timeout(request.timeout()).masterTimeout(request.masterNodeTimeout()), new MetaDataDeleteIndexService.Listener() { @Override public void onResponse(MetaDataDeleteIndexService.Response response) { listener.onResponse(new DeleteIndexResponse(response.acknowledged())); } @Override public void onFailure(Throwable t) { listener.onFailure(t); } }); }
Example 4
Source File: TransportBulkCreateIndicesAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override protected void masterOperation(final BulkCreateIndicesRequest request, final ClusterState state, final ActionListener<BulkCreateIndicesResponse> listener) throws ElasticsearchException { if (request.indices().isEmpty()) { listener.onResponse(new BulkCreateIndicesResponse(true)); return; } final ActionListener<ClusterStateUpdateResponse> stateUpdateListener = new ActionListener<ClusterStateUpdateResponse>() { @Override public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { listener.onResponse(new BulkCreateIndicesResponse(true)); } @Override public void onFailure(Throwable e) { listener.onFailure(e); } }; createIndices(request, stateUpdateListener); }
Example 5
Source File: TransportListStoresAction.java From elasticsearch-learning-to-rank with Apache License 2.0 | 6 votes |
@Override protected void masterOperation(ListStoresActionRequest request, ClusterState state, ActionListener<ListStoresActionResponse> listener) throws Exception { String[] names = indexNameExpressionResolver.concreteIndexNames(state, new ClusterStateRequest().indices(IndexFeatureStore.DEFAULT_STORE, IndexFeatureStore.STORE_PREFIX + "*")); final MultiSearchRequestBuilder req = client.prepareMultiSearch(); final List<Tuple<String, Integer>> versions = new ArrayList<>(); Stream.of(names) .filter(IndexFeatureStore::isIndexStore) .map((s) -> clusterService.state().metaData().getIndices().get(s)) .filter(Objects::nonNull) .filter((im) -> STORE_VERSION_PROP.exists(im.getSettings())) .forEach((m) -> { req.add(countSearchRequest(m)); versions.add(tuple(m.getIndex().getName(),STORE_VERSION_PROP.get(m.getSettings()))); }); if (versions.isEmpty()) { listener.onResponse(new ListStoresActionResponse(Collections.emptyList())); } else { req.execute(wrap((r) -> listener.onResponse(toResponse(r, versions)), listener::onFailure)); } }
Example 6
Source File: TransportISBNFormatAction.java From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void doExecute(ISBNFormatRequest request, ActionListener<ISBNFormatResponse> listener) { ISBNFormatResponse response = new ISBNFormatResponse(); try { standardnumberService.handle(request.getValue(), response); } catch (IllegalArgumentException e) { logger.debug(e.getMessage(), e); response.setInvalid(request.getValue()); } listener.onResponse(response); }
Example 7
Source File: TransportReplicationAction.java From crate with Apache License 2.0 | 5 votes |
@Override public void markShardCopyAsStaleIfNeeded(ShardId shardId, String allocationId, ActionListener<Void> listener) { // This does not need to make the shard stale. The idea is that this // is a non-write operation (something like a refresh or a global // checkpoint sync) and therefore the replica should still be // "alive" if it were to be marked as stale. listener.onResponse(null); }
Example 8
Source File: TransportGetMappingsAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void doMasterOperation(final GetMappingsRequest request, String[] concreteIndices, final ClusterState state, final ActionListener<GetMappingsResponse> listener) { logger.trace("serving getMapping request based on version {}", state.version()); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> result = state.metaData().findMappings( concreteIndices, request.types() ); listener.onResponse(new GetMappingsResponse(result)); }
Example 9
Source File: SyncedFlushService.java From crate with Apache License 2.0 | 5 votes |
private void reportSuccessWithExistingSyncId(ShardId shardId, String existingSyncId, List<ShardRouting> shards, int totalShards, Map<String, PreSyncedFlushResponse> preSyncResponses, ActionListener<ShardsSyncedFlushResult> listener) { final Map<ShardRouting, ShardSyncedFlushResponse> results = new HashMap<>(); for (final ShardRouting shard : shards) { if (preSyncResponses.containsKey(shard.currentNodeId())) { results.put(shard, new ShardSyncedFlushResponse()); } } listener.onResponse(new ShardsSyncedFlushResult(shardId, existingSyncId, totalShards, results)); }
Example 10
Source File: TransportReplicationAction.java From crate with Apache License 2.0 | 5 votes |
@Override public void failShardIfNeeded(ShardRouting replica, String message, Exception exception, ActionListener<Void> listener) { // This does not need to fail the shard. The idea is that this // is a non-write operation (something like a refresh or a global // checkpoint sync) and therefore the replica should still be // "alive" if it were to fail. listener.onResponse(null); }
Example 11
Source File: MultiActionListener.java From crate with Apache License 2.0 | 5 votes |
public MultiActionListener(int numResponses, Supplier<S> stateSupplier, BiConsumer<S, I> accumulator, Function<S, R> finisher, ActionListener<? super R> actionListener) { this.accumulator = accumulator; this.finisher = finisher; this.actionListener = actionListener; this.state = stateSupplier.get(); counter = new AtomicInteger(numResponses); if (numResponses == 0) { actionListener.onResponse(finisher.apply(state)); } }
Example 12
Source File: TransportGetAliasesAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void masterOperation(GetAliasesRequest request, ClusterState state, ActionListener<GetAliasesResponse> listener) { String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); @SuppressWarnings("unchecked") ImmutableOpenMap<String, List<AliasMetaData>> result = (ImmutableOpenMap) state.metaData().findAliases(request.aliases(), concreteIndices); listener.onResponse(new GetAliasesResponse(result)); }
Example 13
Source File: ListAlgorithmsAction.java From elasticsearch-carrot2 with Apache License 2.0 | 5 votes |
@Override protected void doExecute(Task task, ListAlgorithmsActionRequest request, ActionListener<ListAlgorithmsActionResponse> listener) { listener.onResponse(new ListAlgorithmsActionResponse( new ArrayList<>(controllerSingleton.getAlgorithms().keySet()))); }
Example 14
Source File: TransportGetSettingsAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void masterOperation(GetSettingsRequest request, ClusterState state, ActionListener<GetSettingsResponse> listener) { String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); ImmutableOpenMap.Builder<String, Settings> indexToSettingsBuilder = ImmutableOpenMap.builder(); for (String concreteIndex : concreteIndices) { IndexMetaData indexMetaData = state.getMetaData().index(concreteIndex); if (indexMetaData == null) { continue; } Settings settings = SettingsFilter.filterSettings(settingsFilter.getPatterns(), indexMetaData.getSettings()); if (request.humanReadable()) { settings = IndexMetaData.addHumanReadableSettings(settings); } if (!CollectionUtils.isEmpty(request.names())) { Settings.Builder settingsBuilder = Settings.builder(); for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) { if (Regex.simpleMatch(request.names(), entry.getKey())) { settingsBuilder.put(entry.getKey(), entry.getValue()); } } settings = settingsBuilder.build(); } indexToSettingsBuilder.put(concreteIndex, settings); } listener.onResponse(new GetSettingsResponse(indexToSettingsBuilder.build())); }
Example 15
Source File: TransportCreatePartitionsAction.java From crate with Apache License 2.0 | 5 votes |
@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 16
Source File: RecoverySourceHandler.java From crate with Apache License 2.0 | 5 votes |
private void sendBatch(CheckedSupplier<List<Translog.Operation>, IOException> nextBatch, boolean firstBatch, long targetLocalCheckpoint, int totalTranslogOps, long maxSeenAutoIdTimestamp, long maxSeqNoOfUpdatesOrDeletes, ActionListener<Long> listener) throws IOException { final List<Translog.Operation> operations = nextBatch.get(); // send the leftover operations or if no operations were sent, request // the target to respond with its local checkpoint if (operations.isEmpty() == false || firstBatch) { cancellableThreads.execute(() -> recoveryTarget.indexTranslogOperations( operations, totalTranslogOps, maxSeenAutoIdTimestamp, maxSeqNoOfUpdatesOrDeletes, ActionListener.wrap(newCheckpoint -> sendBatch( nextBatch, false, SequenceNumbers.max(targetLocalCheckpoint, newCheckpoint), totalTranslogOps, maxSeenAutoIdTimestamp, maxSeqNoOfUpdatesOrDeletes, listener), listener::onFailure )) ); } else { listener.onResponse(targetLocalCheckpoint); } }
Example 17
Source File: ReplicationOperationTests.java From crate with Apache License 2.0 | 5 votes |
@Override public void markShardCopyAsStaleIfNeeded(ShardId shardId, String allocationId, ActionListener<Void> listener) { if (markedAsStaleCopies.add(allocationId) == false) { fail("replica [" + allocationId + "] was marked as stale twice"); } listener.onResponse(null); }
Example 18
Source File: TransportGetIndexAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected void doMasterOperation(final GetIndexRequest request, String[] concreteIndices, final ClusterState state, final ActionListener<GetIndexResponse> listener) { ImmutableOpenMap<String, List<Entry>> warmersResult = ImmutableOpenMap.of(); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsResult = ImmutableOpenMap.of(); ImmutableOpenMap<String, List<AliasMetaData>> aliasesResult = ImmutableOpenMap.of(); ImmutableOpenMap<String, Settings> settings = ImmutableOpenMap.of(); Feature[] features = request.features(); boolean doneAliases = false; boolean doneMappings = false; boolean doneSettings = false; boolean doneWarmers = false; for (Feature feature : features) { switch (feature) { case WARMERS: if (!doneWarmers) { warmersResult = state.metaData().findWarmers(concreteIndices, request.types(), Strings.EMPTY_ARRAY); doneWarmers = true; } break; case MAPPINGS: if (!doneMappings) { mappingsResult = state.metaData().findMappings(concreteIndices, request.types()); doneMappings = true; } break; case ALIASES: if (!doneAliases) { aliasesResult = state.metaData().findAliases(Strings.EMPTY_ARRAY, concreteIndices); doneAliases = true; } break; case SETTINGS: if (!doneSettings) { ImmutableOpenMap.Builder<String, Settings> settingsMapBuilder = ImmutableOpenMap.builder(); for (String index : concreteIndices) { Settings indexSettings = state.metaData().index(index).getSettings(); if (request.humanReadable()) { indexSettings = IndexMetaData.addHumanReadableSettings(indexSettings); } settingsMapBuilder.put(index, indexSettings); } settings = settingsMapBuilder.build(); doneSettings = true; } break; default: throw new IllegalStateException("feature [" + feature + "] is not valid"); } } listener.onResponse(new GetIndexResponse(concreteIndices, warmersResult, mappingsResult, aliasesResult, settings)); }
Example 19
Source File: VerifyNodeRepositoryAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
public void finishVerification(ActionListener<VerifyResponse> listener, List<DiscoveryNode> nodes, CopyOnWriteArrayList<VerificationFailure> errors) { listener.onResponse(new RepositoriesService.VerifyResponse(nodes.toArray(new DiscoveryNode[nodes.size()]), errors.toArray(new VerificationFailure[errors.size()]))); }
Example 20
Source File: VerifyNodeRepositoryAction.java From crate with Apache License 2.0 | 4 votes |
public void finishVerification(ActionListener<VerifyResponse> listener, List<DiscoveryNode> nodes, CopyOnWriteArrayList<VerificationFailure> errors) { listener.onResponse(new RepositoriesService.VerifyResponse(nodes.toArray(new DiscoveryNode[nodes.size()]), errors.toArray(new VerificationFailure[errors.size()]))); }