use of org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse in project crate by crate.
the class DropTableTask method execute.
@Override
public void execute(final BatchConsumer consumer, Row parameters) {
if (tableInfo.isPartitioned()) {
String templateName = PartitionName.templateName(tableInfo.ident().schema(), tableInfo.ident().name());
deleteTemplateAction.execute(new DeleteIndexTemplateRequest(templateName), new ActionListener<DeleteIndexTemplateResponse>() {
@Override
public void onResponse(DeleteIndexTemplateResponse response) {
if (!response.isAcknowledged()) {
warnNotAcknowledged();
}
if (!tableInfo.partitions().isEmpty()) {
deleteESIndex(tableInfo.ident().indexName(), consumer);
} else {
consumer.accept(RowsBatchIterator.newInstance(ROW_ONE), null);
}
}
@Override
public void onFailure(Throwable e) {
e = ExceptionsHelper.unwrapCause(e);
if (e instanceof IndexTemplateMissingException && !tableInfo.partitions().isEmpty()) {
logger.warn(e.getMessage());
deleteESIndex(tableInfo.ident().indexName(), consumer);
} else {
consumer.accept(null, e);
}
}
});
} else {
deleteESIndex(tableInfo.ident().indexName(), consumer);
}
}
use of org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse in project graylog2-server by Graylog2.
the class IndicesTest method testIndexTemplateCanBeOverridden.
@Test
public void testIndexTemplateCanBeOverridden() throws Exception {
final String customTemplateName = "custom-template";
final IndicesAdminClient client = this.client.admin().indices();
// Create custom index template
final Map<String, Object> customMapping = ImmutableMap.of("_source", ImmutableMap.of("enabled", false), "properties", ImmutableMap.of("message", ImmutableMap.of("type", "string", "index", "not_analyzed")));
final PutIndexTemplateResponse putIndexTemplateResponse = client.preparePutTemplate(customTemplateName).setTemplate(indexSet.getIndexWildcard()).setOrder(1).addMapping(IndexMapping.TYPE_MESSAGE, customMapping).get();
assertThat(putIndexTemplateResponse.isAcknowledged()).isTrue();
// Validate existing index templates
final GetIndexTemplatesResponse getTemplatesResponse = client.prepareGetTemplates().get();
final List<IndexTemplateMetaData> indexTemplates = getTemplatesResponse.getIndexTemplates();
assertThat(indexTemplates).extracting(IndexTemplateMetaData::getName).containsExactly(customTemplateName);
// Create index with custom template
final String testIndexName = "graylog_override_template";
indices.create(testIndexName, indexSet);
// Check index mapping
final GetMappingsResponse indexMappingResponse = client.prepareGetMappings(testIndexName).get();
final String mapping = indexMappingResponse.getMappings().get(testIndexName).get(IndexMapping.TYPE_MESSAGE).source().string();
final ReadContext ctx = JsonPath.parse(mapping);
final boolean sourceEnabled = ctx.read("$.message._source.enabled");
assertThat(sourceEnabled).isFalse();
final String messageField = ctx.read("$.message.properties.message.index");
assertThat(messageField).isEqualTo("not_analyzed");
// Clean up
final DeleteIndexTemplateResponse deleteResponse = client.prepareDeleteTemplate(customTemplateName).get();
assertThat(deleteResponse.isAcknowledged()).isTrue();
indices.delete(testIndexName);
}
use of org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse in project graylog2-server by Graylog2.
the class IndicesTest method testCreateEnsuresIndexTemplateExists.
@Test
public void testCreateEnsuresIndexTemplateExists() throws Exception {
final String templateName = indexSetConfig.indexTemplateName();
final IndicesAdminClient client = this.client.admin().indices();
final GetIndexTemplatesRequest request = client.prepareGetTemplates(templateName).request();
final GetIndexTemplatesResponse responseBefore = client.getTemplates(request).actionGet();
assertThat(responseBefore.getIndexTemplates()).isEmpty();
indices.create("index_template_test", indexSet);
final GetIndexTemplatesResponse responseAfter = client.getTemplates(request).actionGet();
assertThat(responseAfter.getIndexTemplates()).hasSize(1);
final IndexTemplateMetaData templateMetaData = responseAfter.getIndexTemplates().get(0);
assertThat(templateMetaData.getName()).isEqualTo(templateName);
assertThat(templateMetaData.getMappings().keysIt()).containsExactly(IndexMapping.TYPE_MESSAGE);
final DeleteIndexTemplateRequest deleteRequest = client.prepareDeleteTemplate(templateName).request();
final DeleteIndexTemplateResponse deleteResponse = client.deleteTemplate(deleteRequest).actionGet();
assertThat(deleteResponse.isAcknowledged()).isTrue();
indices.delete("index_template_test");
}
use of org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse in project graylog2-server by Graylog2.
the class IndicesTest method testCreateOverwritesIndexTemplate.
@Test
public void testCreateOverwritesIndexTemplate() throws Exception {
final ObjectMapper mapper = new ObjectMapperProvider().get();
final String templateName = indexSetConfig.indexTemplateName();
final IndicesAdminClient client = this.client.admin().indices();
final ImmutableMap<String, Object> beforeMapping = ImmutableMap.of("_source", ImmutableMap.of("enabled", false), "properties", ImmutableMap.of("message", ImmutableMap.of("type", "string", "index", "not_analyzed")));
assertThat(client.preparePutTemplate(templateName).setTemplate(indexSet.getIndexWildcard()).addMapping(IndexMapping.TYPE_MESSAGE, beforeMapping).get().isAcknowledged()).isTrue();
final GetIndexTemplatesResponse responseBefore = client.prepareGetTemplates(templateName).get();
final List<IndexTemplateMetaData> beforeIndexTemplates = responseBefore.getIndexTemplates();
assertThat(beforeIndexTemplates).hasSize(1);
final ImmutableOpenMap<String, CompressedXContent> beforeMappings = beforeIndexTemplates.get(0).getMappings();
final Map<String, Object> actualMapping = mapper.readValue(beforeMappings.get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
});
assertThat(actualMapping.get(IndexMapping.TYPE_MESSAGE)).isEqualTo(beforeMapping);
indices.create("index_template_test", indexSet);
final GetIndexTemplatesResponse responseAfter = client.prepareGetTemplates(templateName).get();
assertThat(responseAfter.getIndexTemplates()).hasSize(1);
final IndexTemplateMetaData templateMetaData = responseAfter.getIndexTemplates().get(0);
assertThat(templateMetaData.getName()).isEqualTo(templateName);
assertThat(templateMetaData.getMappings().keysIt()).containsExactly(IndexMapping.TYPE_MESSAGE);
final Map<String, Object> mapping = mapper.readValue(templateMetaData.getMappings().get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
});
final Map<String, Object> expectedTemplate = new IndexMapping().messageTemplate(indexSet.getIndexWildcard(), indexSetConfig.indexAnalyzer());
assertThat(mapping).isEqualTo(expectedTemplate.get("mappings"));
final DeleteIndexTemplateRequest deleteRequest = client.prepareDeleteTemplate(templateName).request();
final DeleteIndexTemplateResponse deleteResponse = client.deleteTemplate(deleteRequest).actionGet();
assertThat(deleteResponse.isAcknowledged()).isTrue();
indices.delete("index_template_test");
}
Aggregations