Search in sources :

Example 76 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class IndicesServiceTests method testIndexAndTombstoneWithSameNameOnStartup.

/**
     * This test checks an edge case where, if a node had an index (lets call it A with UUID 1), then
     * deleted it (so a tombstone entry for A will exist in the cluster state), then created
     * a new index A with UUID 2, then shutdown, when the node comes back online, it will look at the
     * tombstones for deletions, and it should proceed with trying to delete A with UUID 1 and not
     * throw any errors that the index still exists in the cluster state.  This is a case of ensuring
     * that tombstones that have the same name as current valid indices don't cause confusion by
     * trying to delete an index that exists.
     * See https://github.com/elastic/elasticsearch/issues/18054
     */
public void testIndexAndTombstoneWithSameNameOnStartup() throws Exception {
    final String indexName = "test";
    final Index index = new Index(indexName, UUIDs.randomBase64UUID());
    final IndicesService indicesService = getIndicesService();
    final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()).build();
    final IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName()).settings(idxSettings).numberOfShards(1).numberOfReplicas(0).build();
    final Index tombstonedIndex = new Index(indexName, UUIDs.randomBase64UUID());
    final IndexGraveyard graveyard = IndexGraveyard.builder().addTombstone(tombstonedIndex).build();
    final MetaData metaData = MetaData.builder().put(indexMetaData, true).indexGraveyard(graveyard).build();
    final ClusterState clusterState = new ClusterState.Builder(new ClusterName("testCluster")).metaData(metaData).build();
    // if all goes well, this won't throw an exception, otherwise, it will throw an IllegalStateException
    indicesService.verifyIndexIsDeleted(tombstonedIndex, clusterState);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexGraveyard(org.elasticsearch.cluster.metadata.IndexGraveyard) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 77 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class RestHighLevelClientTests method testInfo.

public void testInfo() throws IOException {
    Header[] headers = RestClientTestUtil.randomHeaders(random(), "Header");
    Response response = mock(Response.class);
    MainResponse testInfo = new MainResponse("nodeName", Version.CURRENT, new ClusterName("clusterName"), "clusterUuid", Build.CURRENT, true);
    when(response.getEntity()).thenReturn(new StringEntity(toXContent(testInfo, XContentType.JSON, false).utf8ToString(), ContentType.APPLICATION_JSON));
    when(restClient.performRequest(anyString(), anyString(), anyMapOf(String.class, String.class), anyObject(), anyVararg())).thenReturn(response);
    MainResponse receivedInfo = restHighLevelClient.info(headers);
    assertEquals(testInfo, receivedInfo);
    verify(restClient).performRequest(eq("GET"), eq("/"), eq(Collections.emptyMap()), Matchers.isNull(HttpEntity.class), argThat(new HeadersVarargMatcher(headers)));
}
Also used : MainResponse(org.elasticsearch.action.main.MainResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) StringEntity(org.apache.http.entity.StringEntity) Header(org.apache.http.Header) HttpEntity(org.apache.http.HttpEntity) MainResponse(org.elasticsearch.action.main.MainResponse) ClusterName(org.elasticsearch.cluster.ClusterName) Matchers.anyString(org.mockito.Matchers.anyString)

Example 78 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class ClusterStateHealthTests method simulateClusterRecoveryStates.

private List<ClusterState> simulateClusterRecoveryStates(final String indexName, final boolean withPreviousAllocationIds, final boolean withPrimaryAllocationFailures) {
    final int numberOfShards = randomIntBetween(1, 5);
    final int numberOfReplicas = randomIntBetween(1, numberOfShards);
    // initial index creation and new routing table info
    IndexMetaData indexMetaData = IndexMetaData.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas).state(IndexMetaData.State.OPEN).build();
    if (withPreviousAllocationIds) {
        final IndexMetaData.Builder idxMetaWithAllocationIds = IndexMetaData.builder(indexMetaData);
        boolean atLeastOne = false;
        for (int i = 0; i < numberOfShards; i++) {
            if (atLeastOne == false || randomBoolean()) {
                idxMetaWithAllocationIds.putInSyncAllocationIds(i, Sets.newHashSet(UUIDs.randomBase64UUID()));
                atLeastOne = true;
            }
        }
        indexMetaData = idxMetaWithAllocationIds.build();
    }
    final MetaData metaData = MetaData.builder().put(indexMetaData, true).build();
    final RoutingTable routingTable = RoutingTable.builder().addAsRecovery(indexMetaData).build();
    ClusterState clusterState = ClusterState.builder(new ClusterName("test_cluster")).metaData(metaData).routingTable(routingTable).build();
    return generateClusterStates(clusterState, indexName, numberOfReplicas, withPrimaryAllocationFailures);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 79 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class ClusterStateHealthTests method simulateIndexCreationStates.

private List<ClusterState> simulateIndexCreationStates(final String indexName, final boolean withPrimaryAllocationFailures) {
    final int numberOfShards = randomIntBetween(1, 5);
    final int numberOfReplicas = randomIntBetween(1, numberOfShards);
    // initial index creation and new routing table info
    final IndexMetaData indexMetaData = IndexMetaData.builder(indexName).settings(settings(Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID())).numberOfShards(numberOfShards).numberOfReplicas(numberOfReplicas).build();
    final MetaData metaData = MetaData.builder().put(indexMetaData, true).build();
    final RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetaData).build();
    ClusterState clusterState = ClusterState.builder(new ClusterName("test_cluster")).metaData(metaData).routingTable(routingTable).build();
    return generateClusterStates(clusterState, indexName, numberOfReplicas, withPrimaryAllocationFailures);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) IndexRoutingTable(org.elasticsearch.cluster.routing.IndexRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 80 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class IndexNameExpressionResolverTests method testIndexOptionsSingleIndexNoExpandWildcards.

public void testIndexOptionsSingleIndexNoExpandWildcards() {
    MetaData.Builder mdBuilder = MetaData.builder().put(indexBuilder("foo").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foobar").putAlias(AliasMetaData.builder("foofoobar"))).put(indexBuilder("foofoo-closed").state(IndexMetaData.State.CLOSE)).put(indexBuilder("foofoo").putAlias(AliasMetaData.builder("barbaz")));
    ClusterState state = ClusterState.builder(new ClusterName("_name")).metaData(mdBuilder).build();
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "baz*");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("baz*"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foo", "baz*");
        fail();
    } catch (IndexNotFoundException e) {
        assertThat(e.getIndex().getName(), equalTo("baz*"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foofoobar");
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foo", "foofoobar");
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("Alias [foofoobar] has more than one indices associated with it"));
    }
    try {
        IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
        indexNameExpressionResolver.concreteIndexNames(context, "foofoo-closed", "foofoobar");
        fail();
    } catch (IndexClosedException e) {
        assertThat(e.getMessage(), equalTo("closed"));
        assertEquals(e.getIndex().getName(), "foofoo-closed");
    }
    IndexNameExpressionResolver.Context context = new IndexNameExpressionResolver.Context(state, IndicesOptions.strictSingleIndexNoExpandForbidClosed());
    String[] results = indexNameExpressionResolver.concreteIndexNames(context, "foo", "barbaz");
    assertEquals(2, results.length);
    assertThat(results, arrayContainingInAnyOrder("foo", "foofoo"));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) IndexClosedException(org.elasticsearch.indices.IndexClosedException) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

ClusterName (org.elasticsearch.cluster.ClusterName)95 ClusterState (org.elasticsearch.cluster.ClusterState)76 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)22 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)20 Settings (org.elasticsearch.common.settings.Settings)20 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Version (org.elasticsearch.Version)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 MetaData (org.elasticsearch.cluster.metadata.MetaData)12 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)12 ArrayList (java.util.ArrayList)11 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)10 List (java.util.List)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 ESTestCase (org.elasticsearch.test.ESTestCase)8