Search in sources :

Example 1 with DeleteIndexTemplateRequest

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);
    }
}
Also used : IndexTemplateMissingException(org.elasticsearch.indices.IndexTemplateMissingException) DeleteIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)

Example 2 with DeleteIndexTemplateRequest

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);
    }
}
Also used : DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) IndexClosedException(org.elasticsearch.indices.IndexClosedException) IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) IOException(java.io.IOException)

Example 3 with DeleteIndexTemplateRequest

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");
}
Also used : DeleteIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Test(org.junit.Test)

Example 4 with DeleteIndexTemplateRequest

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();
}
Also used : AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) DeleteIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)

Example 5 with DeleteIndexTemplateRequest

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));
}
Also used : DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)

Aggregations

DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)7 IOException (java.io.IOException)3 DeleteIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse)3 Map (java.util.Map)2 PutIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest)2 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 ClusterSearchShardsRequest (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest)1 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)1 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)1 ClearIndicesCacheRequest (org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest)1 CloseIndexRequest (org.elasticsearch.action.admin.indices.close.CloseIndexRequest)1