Search in sources :

Example 36 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class TransportMultiTermVectorsAction method doExecute.

@Override
protected void doExecute(Task task, final MultiTermVectorsRequest request, final ActionListener<MultiTermVectorsResponse> listener) {
    ClusterState clusterState = clusterService.state();
    clusterState.blocks().globalBlockedRaiseException(ClusterBlockLevel.READ);
    final AtomicArray<MultiTermVectorsItemResponse> responses = new AtomicArray<>(request.requests.size());
    Map<ShardId, MultiTermVectorsShardRequest> shardRequests = new HashMap<>();
    for (int i = 0; i < request.requests.size(); i++) {
        TermVectorsRequest termVectorsRequest = request.requests.get(i);
        termVectorsRequest.routing(clusterState.metadata().resolveIndexRouting(termVectorsRequest.routing(), termVectorsRequest.index()));
        if (!clusterState.metadata().hasConcreteIndex(termVectorsRequest.index())) {
            responses.set(i, new MultiTermVectorsItemResponse(null, new MultiTermVectorsResponse.Failure(termVectorsRequest.index(), termVectorsRequest.id(), new IndexNotFoundException(termVectorsRequest.index()))));
            continue;
        }
        String concreteSingleIndex = indexNameExpressionResolver.concreteSingleIndex(clusterState, termVectorsRequest).getName();
        if (termVectorsRequest.routing() == null && clusterState.getMetadata().routingRequired(concreteSingleIndex)) {
            responses.set(i, new MultiTermVectorsItemResponse(null, new MultiTermVectorsResponse.Failure(concreteSingleIndex, termVectorsRequest.id(), new RoutingMissingException(concreteSingleIndex, termVectorsRequest.id()))));
            continue;
        }
        ShardId shardId = clusterService.operationRouting().shardId(clusterState, concreteSingleIndex, termVectorsRequest.id(), termVectorsRequest.routing());
        MultiTermVectorsShardRequest shardRequest = shardRequests.get(shardId);
        if (shardRequest == null) {
            shardRequest = new MultiTermVectorsShardRequest(shardId.getIndexName(), shardId.id());
            shardRequest.preference(request.preference);
            shardRequests.put(shardId, shardRequest);
        }
        shardRequest.add(i, termVectorsRequest);
    }
    if (shardRequests.size() == 0) {
        // only failures..
        listener.onResponse(new MultiTermVectorsResponse(responses.toArray(new MultiTermVectorsItemResponse[responses.length()])));
    }
    executeShardAction(listener, responses, shardRequests);
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) AtomicArray(org.opensearch.common.util.concurrent.AtomicArray) HashMap(java.util.HashMap) ShardId(org.opensearch.index.shard.ShardId) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) RoutingMissingException(org.opensearch.action.RoutingMissingException)

Example 37 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class CancelAllocationCommand method execute.

@Override
public RerouteExplanation execute(RoutingAllocation allocation, boolean explain) {
    DiscoveryNode discoNode = allocation.nodes().resolveNode(node);
    ShardRouting shardRouting = null;
    RoutingNodes routingNodes = allocation.routingNodes();
    RoutingNode routingNode = routingNodes.node(discoNode.getId());
    IndexMetadata indexMetadata = null;
    if (routingNode != null) {
        indexMetadata = allocation.metadata().index(index());
        if (indexMetadata == null) {
            throw new IndexNotFoundException(index());
        }
        ShardId shardId = new ShardId(indexMetadata.getIndex(), shardId());
        shardRouting = routingNode.getByShardId(shardId);
    }
    if (shardRouting == null) {
        if (explain) {
            return new RerouteExplanation(this, allocation.decision(Decision.NO, "cancel_allocation_command", "can't cancel " + shardId + ", failed to find it on node " + discoNode));
        }
        throw new IllegalArgumentException("[cancel_allocation] can't cancel " + shardId + ", failed to find it on node " + discoNode);
    }
    if (shardRouting.primary() && allowPrimary == false) {
        if ((shardRouting.initializing() && shardRouting.relocatingNodeId() != null) == false) {
            // only allow cancelling initializing shard of primary relocation without allowPrimary flag
            if (explain) {
                return new RerouteExplanation(this, allocation.decision(Decision.NO, "cancel_allocation_command", "can't cancel " + shardId + " on node " + discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT)));
            }
            throw new IllegalArgumentException("[cancel_allocation] can't cancel " + shardId + " on node " + discoNode + ", shard is primary and " + shardRouting.state().name().toLowerCase(Locale.ROOT));
        }
    }
    routingNodes.failShard(LogManager.getLogger(CancelAllocationCommand.class), shardRouting, new UnassignedInfo(UnassignedInfo.Reason.REROUTE_CANCELLED, null), indexMetadata, allocation.changes());
    // TODO: We don't have to remove a cancelled shard from in-sync set once we have a strict resync implementation.
    allocation.removeAllocationId(shardRouting);
    return new RerouteExplanation(this, allocation.decision(Decision.YES, "cancel_allocation_command", "shard " + shardId + " on node " + discoNode + " can be cancelled"));
}
Also used : ShardId(org.opensearch.index.shard.ShardId) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) RoutingNode(org.opensearch.cluster.routing.RoutingNode) RoutingNodes(org.opensearch.cluster.routing.RoutingNodes) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) RerouteExplanation(org.opensearch.cluster.routing.allocation.RerouteExplanation) ShardRouting(org.opensearch.cluster.routing.ShardRouting) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 38 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class SimpleBlocksIT method testAddBlockToOneMissingIndex.

public void testAddBlockToOneMissingIndex() {
    createIndex("test1");
    final IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareAddBlock(randomAddableBlock(), "test1", "test2").get());
    assertThat(e.getMessage(), is("no such index [test2]"));
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 39 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class SimpleBlocksIT method testAddBlockToMissingIndex.

public void testAddBlockToMissingIndex() {
    IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().admin().indices().prepareAddBlock(randomAddableBlock(), "test").get());
    assertThat(e.getMessage(), is("no such index [test]"));
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 40 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project OpenSearch by opensearch-project.

the class SimpleIndexStateIT method testConsistencyAfterIndexCreationFailure.

public void testConsistencyAfterIndexCreationFailure() {
    logger.info("--> deleting test index....");
    try {
        client().admin().indices().prepareDelete("test").get();
    } catch (IndexNotFoundException ex) {
    // Ignore
    }
    logger.info("--> creating test index with invalid settings ");
    try {
        client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("number_of_shards", "bad")).get();
        fail();
    } catch (IllegalArgumentException ex) {
        assertEquals("Failed to parse value [bad] for setting [index.number_of_shards]", ex.getMessage());
    // Expected
    }
    logger.info("--> creating test index with valid settings ");
    CreateIndexResponse response = client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("number_of_shards", 1)).get();
    assertThat(response.isAcknowledged(), equalTo(true));
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse)

Aggregations

IndexNotFoundException (org.opensearch.index.IndexNotFoundException)107 ActionListener (org.opensearch.action.ActionListener)32 ClusterState (org.opensearch.cluster.ClusterState)26 IOException (java.io.IOException)25 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)25 Map (java.util.Map)23 Client (org.opensearch.client.Client)23 ArrayList (java.util.ArrayList)21 Settings (org.opensearch.common.settings.Settings)21 Logger (org.apache.logging.log4j.Logger)20 List (java.util.List)19 LogManager (org.apache.logging.log4j.LogManager)19 SearchResponse (org.opensearch.action.search.SearchResponse)19 HashMap (java.util.HashMap)18 GetRequest (org.opensearch.action.get.GetRequest)18 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)18 NamedXContentRegistry (org.opensearch.common.xcontent.NamedXContentRegistry)18 ClusterService (org.opensearch.cluster.service.ClusterService)17 XContentParser (org.opensearch.common.xcontent.XContentParser)17 DeleteResponse (org.opensearch.action.delete.DeleteResponse)16