Search in sources :

Example 1 with GetIndexTemplatesResponse

use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.

the class SimpleClusterStateIT method testIndexTemplates.

public void testIndexTemplates() throws Exception {
    client().admin().indices().preparePutTemplate("foo_template").setPatterns(Collections.singletonList("te*")).setOrder(0).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).get();
    client().admin().indices().preparePutTemplate("fuu_template").setPatterns(Collections.singletonList("test*")).setOrder(1).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field2").field("type", "text").field("store", false).endObject().endObject().endObject().endObject()).get();
    ClusterStateResponse clusterStateResponseUnfiltered = client().admin().cluster().prepareState().get();
    assertThat(clusterStateResponseUnfiltered.getState().metadata().templates().size(), is(greaterThanOrEqualTo(2)));
    GetIndexTemplatesResponse getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates("foo_template").get();
    assertIndexTemplateExists(getIndexTemplatesResponse, "foo_template");
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)

Example 2 with GetIndexTemplatesResponse

use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.

the class IndexTemplateBlocksIT method testIndexTemplatesWithBlocks.

public void testIndexTemplatesWithBlocks() throws IOException {
    // creates a simple index template
    client().admin().indices().preparePutTemplate("template_blocks").setPatterns(Collections.singletonList("te*")).setOrder(0).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).execute().actionGet();
    try {
        setClusterReadOnly(true);
        GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates("template_blocks").execute().actionGet();
        assertThat(response.getIndexTemplates(), hasSize(1));
        assertBlocked(client().admin().indices().preparePutTemplate("template_blocks_2").setPatterns(Collections.singletonList("block*")).setOrder(0).addAlias(new Alias("alias_1")));
        assertBlocked(client().admin().indices().prepareDeleteTemplate("template_blocks"));
    } finally {
        setClusterReadOnly(false);
    }
}
Also used : GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Alias(org.opensearch.action.admin.indices.alias.Alias)

Example 3 with GetIndexTemplatesResponse

use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.

the class SimpleIndexTemplateIT method testInvalidSettings.

public void testInvalidSettings() throws Exception {
    // clean all templates setup by the framework.
    client().admin().indices().prepareDeleteTemplate("*").get();
    // check get all templates on an empty index.
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
    assertThat(response.getIndexTemplates(), empty());
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).setSettings(Settings.builder().put("does_not_exist", "test")).get());
    assertEquals("unknown setting [index.does_not_exist] please check that any required plugins are" + " installed, or check the breaking changes documentation for removed settings", e.getMessage());
    response = client().admin().indices().prepareGetTemplates().get();
    assertEquals(0, response.getIndexTemplates().size());
    createIndex("test");
    GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
    assertNull(getSettingsResponse.getIndexToSettings().get("test").get("index.does_not_exist"));
}
Also used : GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)

Example 4 with GetIndexTemplatesResponse

use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.

the class SimpleIndexTemplateIT method testPartitionedTemplate.

public void testPartitionedTemplate() throws Exception {
    // clean all templates setup by the framework.
    client().admin().indices().prepareDeleteTemplate("*").get();
    // check get all templates on an empty index.
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
    assertThat(response.getIndexTemplates(), empty());
    // provide more partitions than shards
    IllegalArgumentException eBadSettings = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).setSettings(Settings.builder().put("index.number_of_shards", "5").put("index.routing_partition_size", "6")).get());
    assertThat(eBadSettings.getMessage(), containsString("partition size [6] should be a positive number " + "less than the number of shards [5]"));
    // provide an invalid mapping for a partitioned index
    IllegalArgumentException eBadMapping = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_2").setPatterns(Collections.singletonList("te*")).addMapping("type", "{\"type\":{\"_routing\":{\"required\":false}}}", XContentType.JSON).setSettings(Settings.builder().put("index.number_of_shards", "6").put("index.routing_partition_size", "3")).get());
    assertThat(eBadMapping.getMessage(), containsString("must have routing required for partitioned index"));
    // no templates yet
    response = client().admin().indices().prepareGetTemplates().get();
    assertEquals(0, response.getIndexTemplates().size());
    // a valid configuration that only provides the partition size
    assertAcked(client().admin().indices().preparePutTemplate("just_partitions").setPatterns(Collections.singletonList("te*")).setSettings(Settings.builder().put("index.routing_partition_size", "6")).get());
    // create an index with too few shards
    IllegalArgumentException eBadIndex = expectThrows(IllegalArgumentException.class, () -> prepareCreate("test_bad", Settings.builder().put("index.number_of_shards", 5).put("index.number_of_routing_shards", 5)).get());
    assertThat(eBadIndex.getMessage(), containsString("partition size [6] should be a positive number " + "less than the number of shards [5]"));
    // finally, create a valid index
    prepareCreate("test_good", Settings.builder().put("index.number_of_shards", 7).put("index.number_of_routing_shards", 7)).get();
    GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test_good").get();
    assertEquals("6", getSettingsResponse.getIndexToSettings().get("test_good").get("index.routing_partition_size"));
}
Also used : GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)

Example 5 with GetIndexTemplatesResponse

use of org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project OpenSearch by opensearch-project.

the class SimpleIndexTemplateIT method testAliasInvalidFilterValidJson.

public void testAliasInvalidFilterValidJson() throws Exception {
    // invalid filter but valid json: put index template works fine, fails during index creation
    client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addAlias(new Alias("invalid_alias").filter("{ \"invalid\": {} }")).get();
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates("template_1").get();
    assertThat(response.getIndexTemplates().size(), equalTo(1));
    assertThat(response.getIndexTemplates().get(0).getAliases().size(), equalTo(1));
    assertThat(response.getIndexTemplates().get(0).getAliases().get("invalid_alias").filter().string(), equalTo("{\"invalid\":{}}"));
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> createIndex("test"));
    assertThat(e.getMessage(), equalTo("failed to parse filter for alias [invalid_alias]"));
    assertThat(e.getCause(), instanceOf(ParsingException.class));
    assertThat(e.getCause().getMessage(), equalTo("unknown query [invalid]"));
}
Also used : Alias(org.opensearch.action.admin.indices.alias.Alias) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) ParsingException(org.opensearch.common.ParsingException)

Aggregations

GetIndexTemplatesResponse (org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)16 Alias (org.opensearch.action.admin.indices.alias.Alias)4 MapperParsingException (org.opensearch.index.mapper.MapperParsingException)3 RestoreSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)2 GetSettingsResponse (org.opensearch.action.admin.indices.settings.get.GetSettingsResponse)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 List (java.util.List)1 Set (java.util.Set)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 SnapshotStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus)1 SnapshotsStatusResponse (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)1 GetStoredScriptResponse (org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptResponse)1 GetIndexTemplatesRequest (org.opensearch.action.admin.indices.template.get.GetIndexTemplatesRequest)1 PutIndexTemplateRequestBuilder (org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder)1 DeletePipelineRequest (org.opensearch.action.ingest.DeletePipelineRequest)1