Search in sources :

Example 1 with PutIndexTemplateRequestBuilder

use of org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder in project OpenSearch by opensearch-project.

the class SimpleIndexTemplateIT method testAliasWithMultipleIndexRoutings.

public void testAliasWithMultipleIndexRoutings() throws Exception {
    PutIndexTemplateRequestBuilder putIndexTemplateRequestBuilder = client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addAlias(new Alias("alias").indexRouting("1,2,3"));
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> putIndexTemplateRequestBuilder.get());
    assertThat(e.getMessage(), equalTo("alias [alias] has several index routing values associated with it"));
}
Also used : Alias(org.opensearch.action.admin.indices.alias.Alias) PutIndexTemplateRequestBuilder(org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder)

Example 2 with PutIndexTemplateRequestBuilder

use of org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder in project OpenSearch by opensearch-project.

the class SimpleIndexTemplateIT method testAliasEmptyName.

public void testAliasEmptyName() throws Exception {
    PutIndexTemplateRequestBuilder putIndexTemplateRequestBuilder = client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addAlias(new Alias("  ").indexRouting("1,2,3"));
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> putIndexTemplateRequestBuilder.get());
    assertThat(e.getMessage(), equalTo("alias name is required"));
}
Also used : Alias(org.opensearch.action.admin.indices.alias.Alias) PutIndexTemplateRequestBuilder(org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder)

Example 3 with PutIndexTemplateRequestBuilder

use of org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder in project OpenSearch by opensearch-project.

the class OpenSearchIntegTestCase method randomIndexTemplate.

/**
 * Creates a randomized index template. This template is used to pass in randomized settings on a
 * per index basis. Allows to enable/disable the randomization for number of shards and replicas
 */
private void randomIndexTemplate() {
    // TODO move settings for random directory etc here into the index based randomized settings.
    if (cluster().size() > 0) {
        Settings.Builder randomSettingsBuilder = setRandomIndexSettings(random(), Settings.builder());
        if (isInternalCluster()) {
            // this is only used by mock plugins and if the cluster is not internal we just can't set it
            randomSettingsBuilder.put(INDEX_TEST_SEED_SETTING.getKey(), random().nextLong());
        }
        randomSettingsBuilder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards()).put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas());
        // if the test class is annotated with SuppressCodecs("*"), it means don't use lucene's codec randomization
        // otherwise, use it, it has assertions and so on that can find bugs.
        SuppressCodecs annotation = getClass().getAnnotation(SuppressCodecs.class);
        if (annotation != null && annotation.value().length == 1 && "*".equals(annotation.value()[0])) {
            randomSettingsBuilder.put("index.codec", randomFrom(CodecService.DEFAULT_CODEC, CodecService.BEST_COMPRESSION_CODEC));
        } else {
            randomSettingsBuilder.put("index.codec", CodecService.LUCENE_DEFAULT_CODEC);
        }
        for (String setting : randomSettingsBuilder.keys()) {
            assertThat("non index. prefix setting set on index template, its a node setting...", setting, startsWith("index."));
        }
        // always default delayed allocation to 0 to make sure we have tests are not delayed
        randomSettingsBuilder.put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), 0);
        if (randomBoolean()) {
            randomSettingsBuilder.put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), randomBoolean());
        }
        PutIndexTemplateRequestBuilder putTemplate = client().admin().indices().preparePutTemplate("random_index_template").setPatterns(Collections.singletonList("*")).setOrder(0).setSettings(randomSettingsBuilder);
        assertAcked(putTemplate.execute().actionGet());
    }
}
Also used : PutIndexTemplateRequestBuilder(org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings) DiskThresholdSettings(org.opensearch.cluster.routing.allocation.DiskThresholdSettings)

Example 4 with PutIndexTemplateRequestBuilder

use of org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder in project OpenSearch by opensearch-project.

the class RolloverIT method testRolloverDryRun.

public void testRolloverDryRun() throws Exception {
    if (randomBoolean()) {
        PutIndexTemplateRequestBuilder putTemplate = client().admin().indices().preparePutTemplate("test_index").setPatterns(Collections.singletonList("test_index-*")).setOrder(-1).setSettings(Settings.builder().put(AutoExpandReplicas.SETTING.getKey(), "0-all"));
        assertAcked(putTemplate.get());
    }
    assertAcked(prepareCreate("test_index-1").addAlias(new Alias("test_alias")).get());
    index("test_index-1", "type1", "1", "field", "value");
    flush("test_index-1");
    ensureGreen();
    Logger allocationServiceLogger = LogManager.getLogger(AllocationService.class);
    final RolloverResponse response;
    try (MockLogAppender appender = MockLogAppender.createForLoggers(allocationServiceLogger)) {
        appender.addExpectation(new MockLogAppender.UnseenEventExpectation("no related message logged on dry run", AllocationService.class.getName(), Level.INFO, "*test_index*"));
        response = client().admin().indices().prepareRolloverIndex("test_alias").dryRun(true).get();
        appender.assertAllExpectationsMatched();
    }
    assertThat(response.getOldIndex(), equalTo("test_index-1"));
    assertThat(response.getNewIndex(), equalTo("test_index-000002"));
    assertThat(response.isDryRun(), equalTo(true));
    assertThat(response.isRolledOver(), equalTo(false));
    assertThat(response.getConditionStatus().size(), equalTo(0));
    final ClusterState state = client().admin().cluster().prepareState().get().getState();
    final IndexMetadata oldIndex = state.metadata().index("test_index-1");
    assertTrue(oldIndex.getAliases().containsKey("test_alias"));
    final IndexMetadata newIndex = state.metadata().index("test_index-000002");
    assertNull(newIndex);
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) MockLogAppender(org.opensearch.test.MockLogAppender) Alias(org.opensearch.action.admin.indices.alias.Alias) PutIndexTemplateRequestBuilder(org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder) Logger(org.apache.logging.log4j.Logger) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 5 with PutIndexTemplateRequestBuilder

use of org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder in project OpenSearch by opensearch-project.

the class SimpleIndexTemplateIT method testAliasInvalidFilterInvalidJson.

public void testAliasInvalidFilterInvalidJson() throws Exception {
    // invalid json: put index template fails
    PutIndexTemplateRequestBuilder putIndexTemplateRequestBuilder = client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addAlias(new Alias("invalid_alias").filter("abcde"));
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> putIndexTemplateRequestBuilder.get());
    assertThat(e.getMessage(), equalTo("failed to parse filter for alias [invalid_alias]"));
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates("template_1").get();
    assertThat(response.getIndexTemplates().size(), equalTo(0));
}
Also used : Alias(org.opensearch.action.admin.indices.alias.Alias) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse) PutIndexTemplateRequestBuilder(org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder)

Aggregations

PutIndexTemplateRequestBuilder (org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder)5 Alias (org.opensearch.action.admin.indices.alias.Alias)4 Logger (org.apache.logging.log4j.Logger)1 GetIndexTemplatesResponse (org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)1 ClusterState (org.opensearch.cluster.ClusterState)1 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)1 DiskThresholdSettings (org.opensearch.cluster.routing.allocation.DiskThresholdSettings)1 Settings (org.opensearch.common.settings.Settings)1 IndexSettings (org.opensearch.index.IndexSettings)1 MockLogAppender (org.opensearch.test.MockLogAppender)1