use of org.elasticsearch.index.IndexNotFoundException in project metron by apache.
the class ElasticsearchMetaAlertDaoTest method testUpdateShouldThrowExceptionOnMissingSensorIndex.
@Test
public void testUpdateShouldThrowExceptionOnMissingSensorIndex() throws Exception {
ElasticsearchDao elasticsearchDao = mock(ElasticsearchDao.class);
ElasticsearchMetaAlertRetrieveLatestDao elasticsearchMetaAlertRetrieveLatestDao = mock(ElasticsearchMetaAlertRetrieveLatestDao.class);
MetaAlertConfig metaAlertConfig = mock(MetaAlertConfig.class);
ElasticsearchMetaAlertUpdateDao emauDao = spy(new ElasticsearchMetaAlertUpdateDao(elasticsearchDao, elasticsearchMetaAlertRetrieveLatestDao, metaAlertConfig, 1));
doThrow(new IndexNotFoundException("bro")).when(emauDao).getMetaAlertsForAlert("alert_one");
Document update = new Document(new HashMap<>(), "alert_one", "", 0L);
assertThrows(IndexNotFoundException.class, () -> emauDao.update(update, Optional.empty()));
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class InternalBlobTableInfoFactory method resolveIndexMetadata.
private IndexMetadata resolveIndexMetadata(String tableName, ClusterState state) {
String indexName = BlobIndex.fullIndexName(tableName);
Index index;
try {
index = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), indexName)[0];
} catch (IndexNotFoundException ex) {
throw new RelationUnknown(indexName, ex);
}
return state.metadata().index(index);
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class RoutingProvider method forIndices.
public Routing forIndices(ClusterState state, String[] concreteIndices, Map<String, Set<String>> routingValuesByIndex, boolean ignoreMissingShards, ShardSelection shardSelection) {
Set<IndexShardRoutingTable> shards;
try {
shards = computeTargetedShards(state, concreteIndices, routingValuesByIndex);
} catch (IndexNotFoundException e) {
return new Routing(Collections.emptyMap());
}
Map<String, Map<String, IntIndexedContainer>> locations = new TreeMap<>();
for (IndexShardRoutingTable shard : shards) {
final ShardIterator shardIt;
switch(shardSelection) {
case ANY:
if (awarenessAttributes.isEmpty()) {
shardIt = shard.activeInitializingShardsIt(seed);
} else {
shardIt = shard.preferAttributesActiveInitializingShardsIt(awarenessAttributes, state.getNodes(), seed);
}
break;
case PRIMARIES:
shardIt = shard.primaryActiveInitializingShardIt();
break;
default:
throw new AssertionError("Invalid ShardSelection: " + shardSelection);
}
fillLocationsFromShardIterator(ignoreMissingShards, locations, shardIt);
}
return new Routing(locations);
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class InsertFromValues method execute.
private CompletableFuture<ShardResponse.CompressedResult> execute(NodeLimits nodeLimits, ClusterState state, Collection<ShardUpsertRequest> shardUpsertRequests, TransportShardUpsertAction shardUpsertAction, ScheduledExecutorService scheduler) {
ShardResponse.CompressedResult compressedResult = new ShardResponse.CompressedResult();
if (shardUpsertRequests.isEmpty()) {
return CompletableFuture.completedFuture(compressedResult);
}
CompletableFuture<ShardResponse.CompressedResult> result = new CompletableFuture<>();
AtomicInteger numRequests = new AtomicInteger(shardUpsertRequests.size());
AtomicReference<Throwable> lastFailure = new AtomicReference<>(null);
Consumer<ShardUpsertRequest> countdown = request -> {
if (numRequests.decrementAndGet() == 0) {
Throwable throwable = lastFailure.get();
if (throwable == null) {
result.complete(compressedResult);
} else {
throwable = SQLExceptions.unwrap(throwable, t -> t instanceof RuntimeException);
// we want to report duplicate key exceptions
if (!SQLExceptions.isDocumentAlreadyExistsException(throwable) && (partitionWasDeleted(throwable, request.index()) || partitionClosed(throwable, request.index()) || mixedArgumentTypesFailure(throwable))) {
result.complete(compressedResult);
} else {
result.completeExceptionally(throwable);
}
}
}
};
for (ShardUpsertRequest request : shardUpsertRequests) {
String nodeId;
try {
nodeId = state.routingTable().shardRoutingTable(request.shardId()).primaryShard().currentNodeId();
} catch (IndexNotFoundException e) {
lastFailure.set(e);
if (!IndexParts.isPartitioned(request.index())) {
synchronized (compressedResult) {
compressedResult.markAsFailed(request.items());
}
}
countdown.accept(request);
continue;
}
final ConcurrencyLimit nodeLimit = nodeLimits.get(nodeId);
final long startTime = nodeLimit.startSample();
ActionListener<ShardResponse> listener = new ActionListener<>() {
@Override
public void onResponse(ShardResponse shardResponse) {
Throwable throwable = shardResponse.failure();
if (throwable == null) {
nodeLimit.onSample(startTime, false);
synchronized (compressedResult) {
compressedResult.update(shardResponse);
}
} else {
nodeLimit.onSample(startTime, true);
lastFailure.set(throwable);
}
countdown.accept(request);
}
@Override
public void onFailure(Exception e) {
nodeLimit.onSample(startTime, true);
Throwable t = SQLExceptions.unwrap(e);
if (!partitionWasDeleted(t, request.index())) {
synchronized (compressedResult) {
compressedResult.markAsFailed(request.items());
}
}
lastFailure.set(t);
countdown.accept(request);
}
};
shardUpsertAction.execute(request, new RetryListener<>(scheduler, l -> shardUpsertAction.execute(request, l), listener, BackoffPolicy.limitedDynamic(nodeLimit)));
}
return result;
}
use of org.elasticsearch.index.IndexNotFoundException in project crate by crate.
the class InsertFromValues method resolveAndGroupShardRequests.
private static <TReq extends ShardRequest<TReq, TItem>, TItem extends ShardRequest.Item> Map<ShardLocation, TReq> resolveAndGroupShardRequests(ShardedRequests<TReq, TItem> shardedRequests, ClusterService clusterService) {
var itemsByMissingIndex = shardedRequests.itemsByMissingIndex().entrySet().iterator();
while (itemsByMissingIndex.hasNext()) {
var entry = itemsByMissingIndex.next();
var index = entry.getKey();
var requestItems = entry.getValue();
var requestItemsIterator = requestItems.iterator();
while (requestItemsIterator.hasNext()) {
var itemAndRoutingAndSourceInfo = requestItemsIterator.next();
ShardLocation shardLocation;
try {
shardLocation = getShardLocation(index, itemAndRoutingAndSourceInfo.item().id(), itemAndRoutingAndSourceInfo.routing(), clusterService);
} catch (IndexNotFoundException e) {
if (IndexParts.isPartitioned(index)) {
requestItemsIterator.remove();
continue;
} else {
throw e;
}
}
shardedRequests.add(itemAndRoutingAndSourceInfo.item(), 0, shardLocation, null);
requestItemsIterator.remove();
}
if (requestItems.isEmpty()) {
itemsByMissingIndex.remove();
}
}
return shardedRequests.itemsByShard();
}
Aggregations