use of org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest 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.DeleteIndexTemplateRequest in project graylog2-server by Graylog2.
the class Indices method deleteIndexTemplate.
public void deleteIndexTemplate(IndexSet indexSet) {
final String templateName = indexSet.getConfig().indexTemplateName();
final DeleteIndexTemplateRequest deleteRequest = c.admin().indices().prepareDeleteTemplate(templateName).request();
try {
final boolean acknowledged = c.admin().indices().deleteTemplate(deleteRequest).actionGet().isAcknowledged();
if (acknowledged) {
LOG.info("Deleted Graylog index template \"{}\" in Elasticsearch.", templateName);
}
} catch (Exception e) {
LOG.error("Unable to delete the Graylog index template: " + templateName, e);
}
}
use of org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest 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.DeleteIndexTemplateRequest in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method deleteIndexTemplate.
@Override
public boolean deleteIndexTemplate(String templateName) {
final DeleteIndexTemplateRequest request = new DeleteIndexTemplateRequest(templateName);
final AcknowledgedResponse result = client.execute((c, requestOptions) -> c.indices().deleteTemplate(request, requestOptions), "Unable to delete index template " + templateName);
return result.isAcknowledged();
}
use of org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest in project elasticsearch by elastic.
the class RestDeleteIndexTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
DeleteIndexTemplateRequest deleteIndexTemplateRequest = new DeleteIndexTemplateRequest(request.param("name"));
deleteIndexTemplateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexTemplateRequest.masterNodeTimeout()));
return channel -> client.admin().indices().deleteTemplate(deleteIndexTemplateRequest, new AcknowledgedRestListener<>(channel));
}
Aggregations