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"));
}
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"));
}
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());
}
}
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);
}
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));
}
Aggregations