Search in sources :

Example 1 with IndexNotFoundException

use of org.opensearch.index.IndexNotFoundException in project fess-crawler by codelibs.

the class AbstractCrawlerService method createMapping.

protected void createMapping(final String mappingName) {
    boolean exists = false;
    try {
        final IndicesExistsResponse response = fesenClient.get(c -> c.admin().indices().prepareExists(index).execute());
        exists = response.isExists();
    } catch (final IndexNotFoundException e) {
    // ignore
    }
    if (!exists) {
        final CreateIndexResponse indexResponse = fesenClient.get(c -> {
            final String source;
            if (numberOfReplicas > 0) {
                source = "{\"settings\":{\"index\":{\"number_of_shards\":" + numberOfShards + ",\"number_of_replicas\":0,\"auto_expand_replicas\":\"0-" + numberOfReplicas + "\"}}}";
            } else {
                source = "{\"settings\":{\"index\":{\"number_of_shards\":" + numberOfShards + ",\"number_of_replicas\":" + numberOfReplicas + "}}}";
            }
            return c.admin().indices().prepareCreate(index).setSource(source, XContentType.JSON).execute();
        });
        if (indexResponse.isAcknowledged()) {
            logger.info("Created {} index.", index);
        } else if (logger.isDebugEnabled()) {
            logger.debug("Failed to create {} index.", index);
        }
    }
    final GetMappingsResponse getMappingsResponse = fesenClient.get(c -> c.admin().indices().prepareGetMappings(index).execute());
    final ImmutableOpenMap<String, MappingMetadata> indexMappings = getMappingsResponse.mappings().get(index);
    if (indexMappings == null || !indexMappings.containsKey("properties")) {
        final AcknowledgedResponse putMappingResponse = fesenClient.get(c -> {
            final String source = FileUtil.readText("mapping/" + mappingName + ".json");
            return c.admin().indices().preparePutMapping(index).setSource(source, XContentType.JSON).execute();
        });
        if (putMappingResponse.isAcknowledged()) {
            logger.info("Created {} mapping.", index);
        } else {
            logger.warn("Failed to create {} mapping.", index);
        }
    } else if (logger.isDebugEnabled()) {
        logger.debug("{} mapping exists.", index);
    }
}
Also used : IndicesExistsResponse(org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 2 with IndexNotFoundException

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

the class SimpleClusterStateIT method testIndicesOptionsOnAllowNoIndicesFalse.

public void testIndicesOptionsOnAllowNoIndicesFalse() throws Exception {
    // empty wildcard expansion throws exception when allowNoIndices is turned off
    IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, false, true, false);
    try {
        client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("a*").setIndicesOptions(allowNoIndices).get();
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), is("no such index [a*]"));
    }
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException) IndicesOptions(org.opensearch.action.support.IndicesOptions)

Example 3 with IndexNotFoundException

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

the class SimpleClusterStateIT method testIndicesIgnoreUnavailableFalse.

public void testIndicesIgnoreUnavailableFalse() throws Exception {
    // ignore_unavailable set to false throws exception when allowNoIndices is turned off
    IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false);
    try {
        client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("fzzbzz").setIndicesOptions(allowNoIndices).get();
        fail("Expected IndexNotFoundException");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), is("no such index [fzzbzz]"));
    }
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException) IndicesOptions(org.opensearch.action.support.IndicesOptions)

Example 4 with IndexNotFoundException

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

the class PrimaryAllocationIT method testForceStaleReplicaToBePromotedForMissingIndex.

public void testForceStaleReplicaToBePromotedForMissingIndex() {
    internalCluster().startMasterOnlyNode(Settings.EMPTY);
    final String dataNode = internalCluster().startDataOnlyNode();
    final String idxName = "test";
    IndexNotFoundException ex = expectThrows(IndexNotFoundException.class, () -> client().admin().cluster().prepareReroute().add(new AllocateStalePrimaryAllocationCommand(idxName, 0, dataNode, true)).get());
    assertThat(ex.getIndex().getName(), equalTo(idxName));
}
Also used : AllocateStalePrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand) IndexNotFoundException(org.opensearch.index.IndexNotFoundException)

Example 5 with IndexNotFoundException

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

the class TransportClusterHealthAction method prepareResponse.

static int prepareResponse(final ClusterHealthRequest request, final ClusterHealthResponse response, final ClusterState clusterState, final IndexNameExpressionResolver indexNameExpressionResolver) {
    int waitForCounter = 0;
    if (request.waitForStatus() != null && response.getStatus().value() <= request.waitForStatus().value()) {
        waitForCounter++;
    }
    if (request.waitForNoRelocatingShards() && response.getRelocatingShards() == 0) {
        waitForCounter++;
    }
    if (request.waitForNoInitializingShards() && response.getInitializingShards() == 0) {
        waitForCounter++;
    }
    if (request.waitForActiveShards().equals(ActiveShardCount.NONE) == false) {
        ActiveShardCount waitForActiveShards = request.waitForActiveShards();
        assert waitForActiveShards.equals(ActiveShardCount.DEFAULT) == false : "waitForActiveShards must not be DEFAULT on the request object, instead it should be NONE";
        if (waitForActiveShards.equals(ActiveShardCount.ALL)) {
            if (response.getUnassignedShards() == 0 && response.getInitializingShards() == 0) {
                // if we are waiting for all shards to be active, then the num of unassigned and num of initializing shards must be 0
                waitForCounter++;
            }
        } else if (waitForActiveShards.enoughShardsActive(response.getActiveShards())) {
            // there are enough active shards to meet the requirements of the request
            waitForCounter++;
        }
    }
    if (CollectionUtils.isEmpty(request.indices()) == false) {
        try {
            indexNameExpressionResolver.concreteIndexNames(clusterState, IndicesOptions.strictExpand(), request);
            waitForCounter++;
        } catch (IndexNotFoundException e) {
            // no indices, make sure its RED
            response.setStatus(ClusterHealthStatus.RED);
        // missing indices, wait a bit more...
        }
    }
    if (!request.waitForNodes().isEmpty()) {
        if (request.waitForNodes().startsWith(">=")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(2));
            if (response.getNumberOfNodes() >= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("ge(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() >= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("<=")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(2));
            if (response.getNumberOfNodes() <= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("le(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() <= expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith(">")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(1));
            if (response.getNumberOfNodes() > expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("gt(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() > expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("<")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(1));
            if (response.getNumberOfNodes() < expected) {
                waitForCounter++;
            }
        } else if (request.waitForNodes().startsWith("lt(")) {
            int expected = Integer.parseInt(request.waitForNodes().substring(3, request.waitForNodes().length() - 1));
            if (response.getNumberOfNodes() < expected) {
                waitForCounter++;
            }
        } else {
            int expected = Integer.parseInt(request.waitForNodes());
            if (response.getNumberOfNodes() == expected) {
                waitForCounter++;
            }
        }
    }
    return waitForCounter;
}
Also used : IndexNotFoundException(org.opensearch.index.IndexNotFoundException) ActiveShardCount(org.opensearch.action.support.ActiveShardCount)

Aggregations

IndexNotFoundException (org.opensearch.index.IndexNotFoundException)64 ClusterState (org.opensearch.cluster.ClusterState)25 ClusterName (org.opensearch.cluster.ClusterName)16 Matchers.containsString (org.hamcrest.Matchers.containsString)15 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)15 ArrayList (java.util.ArrayList)9 IndicesOptions (org.opensearch.action.support.IndicesOptions)9 Index (org.opensearch.index.Index)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)7 ShardRouting (org.opensearch.cluster.routing.ShardRouting)7 IOException (java.io.IOException)6 ActionListener (org.opensearch.action.ActionListener)6 Settings (org.opensearch.common.settings.Settings)6 ShardId (org.opensearch.index.shard.ShardId)6 List (java.util.List)5 Map (java.util.Map)5 CreateIndexResponse (org.opensearch.action.admin.indices.create.CreateIndexResponse)5 CountDownLatch (java.util.concurrent.CountDownLatch)4