Search in sources :

Example 21 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project elasticsearch by elastic.

the class SimpleIndexTemplateIT method testBrokenMapping.

public void testBrokenMapping() 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());
    MapperParsingException e = expectThrows(MapperParsingException.class, () -> client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addMapping("type1", "{\"foo\": \"abcde\"}", XContentType.JSON).get());
    assertThat(e.getMessage(), containsString("Failed to parse mapping "));
    response = client().admin().indices().prepareGetTemplates().get();
    assertThat(response.getIndexTemplates(), hasSize(0));
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)

Example 22 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project elasticsearch by elastic.

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.elasticsearch.action.admin.indices.alias.Alias) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) PutIndexTemplateRequestBuilder(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder)

Example 23 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testRestoreTemplates.

public void testRestoreTemplates() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())));
    logger.info("-->  creating test template");
    assertThat(client.admin().indices().preparePutTemplate("test-template").setPatterns(Collections.singletonList("te*")).addMapping("test-mapping", XContentFactory.jsonBuilder().startObject().startObject("test-mapping").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).get().isAcknowledged(), equalTo(true));
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setIndices().setWaitForCompletion(true).get();
    assertThat(createSnapshotResponse.getSnapshotInfo().totalShards(), equalTo(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(0));
    assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    logger.info("-->  delete test template");
    assertThat(client.admin().indices().prepareDeleteTemplate("test-template").get().isAcknowledged(), equalTo(true));
    GetIndexTemplatesResponse getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates().get();
    assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template");
    logger.info("--> restore cluster state");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setRestoreGlobalState(true).execute().actionGet();
    // We don't restore any indices here
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), equalTo(0));
    logger.info("--> check that template is restored");
    getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates().get();
    assertIndexTemplateExists(getIndexTemplatesResponse, "test-template");
}
Also used : CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 24 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.

the class TableAliasIntegrationTest method testPartitionedTableKeepsAliasAfterSchemaUpdate.

@Test
public void testPartitionedTableKeepsAliasAfterSchemaUpdate() throws Exception {
    execute("create table t (name string, p string) partitioned by (p) " + "clustered into 2 shards with (number_of_replicas = 0)");
    ensureYellow();
    execute("insert into t (name, p) values ('Arthur', 'a')");
    execute("insert into t (name, p) values ('Trillian', 'a')");
    execute("alter table t add column age integer");
    execute("insert into t (name, p) values ('Marvin', 'b')");
    waitNoPendingTasksOnAll();
    refresh();
    execute("select count(*) from t");
    assertThat(response.rowCount(), is(1L));
    assertThat((Long) response.rows()[0][0], is(3L));
    GetIndexTemplatesResponse indexTemplatesResponse = client().admin().indices().prepareGetTemplates(".partitioned.t.").execute().actionGet();
    IndexTemplateMetaData indexTemplateMetaData = indexTemplatesResponse.getIndexTemplates().get(0);
    AliasMetaData t = indexTemplateMetaData.aliases().get("t");
    assertThat(t.alias(), is("t"));
    execute("select partitioned_by from information_schema.tables where table_name = 't'");
    assertThat((String) ((Object[]) response.rows()[0][0])[0], is("p"));
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) Test(org.junit.Test)

Example 25 with GetIndexTemplatesResponse

use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project crate by crate.

the class ColumnPolicyIntegrationTest method testStrictPartitionedTableUpdate.

@Test
public void testStrictPartitionedTableUpdate() throws Exception {
    execute("create table numbers (" + "  num int, " + "  odd boolean," + "  prime boolean" + ") partitioned by (odd) with (column_policy='strict', number_of_replicas=0)");
    ensureYellow();
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates(PartitionName.templateName(null, "numbers")).execute().actionGet();
    assertThat(response.getIndexTemplates().size(), is(1));
    IndexTemplateMetaData template = response.getIndexTemplates().get(0);
    CompressedXContent mappingStr = template.mappings().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(mappingStr, is(notNullValue()));
    Tuple<XContentType, Map<String, Object>> typeAndMap = XContentHelper.convertToMap(mappingStr.compressedReference(), false);
    @SuppressWarnings("unchecked") Map<String, Object> mapping = (Map<String, Object>) typeAndMap.v2().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(String.valueOf(mapping.get("dynamic")), is(ColumnPolicy.STRICT.value()));
    execute("insert into numbers (num, odd, prime) values (?, ?, ?)", new Object[] { 6, true, false });
    execute("refresh table numbers");
    MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("numbers", Arrays.asList(new BytesRef("true"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
    assertThat(String.valueOf(partitionMetaData.getSourceAsMap().get("dynamic")), is(ColumnPolicy.STRICT.value()));
    expectedException.expect(SQLActionException.class);
    expectedException.expectMessage("Column perfect unknown");
    execute("update numbers set num=?, perfect=? where num=6", new Object[] { 28, true });
}
Also used : MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) PartitionName(io.crate.metadata.PartitionName) XContentType(org.elasticsearch.common.xcontent.XContentType) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) HashMap(java.util.HashMap) Map(java.util.Map) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Aggregations

GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)35 Test (org.junit.Test)18 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)11 PartitionName (io.crate.metadata.PartitionName)10 BytesRef (org.apache.lucene.util.BytesRef)10 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)7 Settings (org.elasticsearch.common.settings.Settings)7 Map (java.util.Map)5 GetIndexTemplatesRequest (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest)5 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)5 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)5 HashMap (java.util.HashMap)4 Alias (org.elasticsearch.action.admin.indices.alias.Alias)4 XContentType (org.elasticsearch.common.xcontent.XContentType)4 DeleteIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse)3 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)3 MapperParsingException (org.elasticsearch.index.mapper.MapperParsingException)3 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)2 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)2 DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)2