Search in sources :

Example 36 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class TemplateUpgradeService method upgradeTemplates.

void upgradeTemplates(Map<String, BytesReference> changes, Set<String> deletions) {
    final AtomicBoolean anyUpgradeFailed = new AtomicBoolean(false);
    for (Map.Entry<String, BytesReference> change : changes.entrySet()) {
        PutIndexTemplateRequest request = new PutIndexTemplateRequest(change.getKey()).source(change.getValue(), XContentType.JSON);
        request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
        client.admin().indices().putTemplate(request, new ActionListener<AcknowledgedResponse>() {

            @Override
            public void onResponse(AcknowledgedResponse response) {
                if (response.isAcknowledged() == false) {
                    anyUpgradeFailed.set(true);
                    LOGGER.warn("Error updating template [{}], request was not acknowledged", change.getKey());
                }
                tryFinishUpgrade(anyUpgradeFailed);
            }

            @Override
            public void onFailure(Exception e) {
                anyUpgradeFailed.set(true);
                LOGGER.warn(new ParameterizedMessage("Error updating template [{}]", change.getKey()), e);
                tryFinishUpgrade(anyUpgradeFailed);
            }
        });
    }
    for (String template : deletions) {
        DeleteIndexTemplateRequest request = new DeleteIndexTemplateRequest(template);
        request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
        client.admin().indices().deleteTemplate(request, new ActionListener<AcknowledgedResponse>() {

            @Override
            public void onResponse(AcknowledgedResponse response) {
                if (response.isAcknowledged() == false) {
                    anyUpgradeFailed.set(true);
                    LOGGER.warn("Error deleting template [{}], request was not acknowledged", template);
                }
                tryFinishUpgrade(anyUpgradeFailed);
            }

            @Override
            public void onFailure(Exception e) {
                anyUpgradeFailed.set(true);
                if (e instanceof IndexTemplateMissingException == false) {
                    // we might attempt to delete the same template from different nodes - so that's ok if template doesn't exist
                    // otherwise we need to warn
                    LOGGER.warn(new ParameterizedMessage("Error deleting template [{}]", template), e);
                }
                tryFinishUpgrade(anyUpgradeFailed);
            }
        });
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) IndexTemplateMissingException(org.elasticsearch.indices.IndexTemplateMissingException) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) IOException(java.io.IOException) IndexTemplateMissingException(org.elasticsearch.indices.IndexTemplateMissingException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 37 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.

@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
    expectedException.expect(RepositoryException.class);
    // add repo to cluster service so that it exists..
    RepositoriesMetadata repos = new RepositoriesMetadata(Collections.singletonList(new RepositoryMetadata("repo1", "fs", Settings.EMPTY)));
    ClusterState state = ClusterState.builder(new ClusterName("dummy")).metadata(Metadata.builder().putCustom(RepositoriesMetadata.TYPE, repos)).build();
    ClusterServiceUtils.setState(clusterService, state);
    IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver();
    final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
    MockTransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, THREAD_POOL, clusterService.getClusterSettings());
    TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {

        @Override
        protected void doExecute(DeleteRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
            deleteRepoCalled.set(true);
            listener.onResponse(mock(AcknowledgedResponse.class));
        }
    };
    TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(transportService, clusterService, mock(RepositoriesService.class), THREAD_POOL, indexNameExpressionResolver) {

        @Override
        protected void doExecute(PutRepositoryRequest request, ActionListener<AcknowledgedResponse> listener) {
            listener.onFailure(new RepositoryException(request.name(), "failure"));
        }
    };
    RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
    try {
        PutRepositoryRequest request = new PutRepositoryRequest("repo1");
        request.type("fs");
        repositoryService.execute(request).get(10, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        assertThat(deleteRepoCalled.get(), is(true));
        throw e.getCause();
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MockTransportService(org.elasticsearch.test.transport.MockTransportService) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RepositoryException(org.elasticsearch.repositories.RepositoryException) RepositoriesMetadata(org.elasticsearch.cluster.metadata.RepositoriesMetadata) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActionListener(org.elasticsearch.action.ActionListener) RepositoryMetadata(org.elasticsearch.cluster.metadata.RepositoryMetadata) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportPutRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction) ExecutionException(java.util.concurrent.ExecutionException) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 38 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class TransportCreatePartitionsActionTest method testCreateBulkIndicesIgnoreExistingSame.

@Test
public void testCreateBulkIndicesIgnoreExistingSame() throws Exception {
    List<String> indices = Arrays.asList("index1", "index2", "index3", "index1");
    AcknowledgedResponse response = action.execute(new CreatePartitionsRequest(indices, UUID.randomUUID())).get();
    assertThat(response.isAcknowledged(), is(true));
    Metadata indexMetadata = internalCluster().clusterService().state().metadata();
    for (String index : indices) {
        assertThat(indexMetadata.hasIndex(index), is(true));
    }
    AcknowledgedResponse response2 = action.execute(new CreatePartitionsRequest(indices, UUID.randomUUID())).get();
    assertThat(response2.isAcknowledged(), is(true));
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Metadata(org.elasticsearch.cluster.metadata.Metadata) Test(org.junit.Test)

Example 39 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project crate by crate.

the class MinThreadsSnapshotRestoreIT method testConcurrentSnapshotDeletionsNotAllowed.

public void testConcurrentSnapshotDeletionsNotAllowed() throws Exception {
    logger.info("--> creating repository");
    assertAcked(client().admin().cluster().preparePutRepository("repo").setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()).put("random", randomAlphaOfLength(10)).put("wait_after_unblock", 200)).get());
    logger.info("--> snapshot twice");
    execute("create table doc.test1 (x integer) clustered into 1 shards with (number_of_replicas=0)");
    for (int i = 0; i < 10; i++) {
        execute("insert into doc.test1 values(?)", new Object[] { i });
    }
    refresh();
    execute("create snapshot repo.snapshot1 all WITH (wait_for_completion=true)");
    execute("create table doc.test2(x integer) clustered into 1 shards with (number_of_replicas=0)");
    for (int i = 0; i < 10; i++) {
        execute("insert into doc.test2 values(?)", new Object[] { i });
    }
    refresh();
    execute("create snapshot repo.snapshot2 all WITH (wait_for_completion=true)");
    String blockedNode = internalCluster().getMasterName();
    ((MockRepository) internalCluster().getInstance(RepositoriesService.class, blockedNode).repository("repo")).blockOnDataFiles(true);
    logger.info("--> start deletion of second snapshot");
    ActionFuture<AcknowledgedResponse> future = client().admin().cluster().prepareDeleteSnapshot("repo", "snapshot2").execute();
    logger.info("--> waiting for block to kick in on node [{}]", blockedNode);
    waitForBlock(blockedNode, "repo", TimeValue.timeValueSeconds(10));
    logger.info("--> try deleting the first snapshot, should fail because there is already a deletion is in progress");
    try {
        execute("drop snapshot repo.snapshot1");
        fail("should not be able to delete snapshots concurrently");
    } catch (ConcurrentSnapshotExecutionException e) {
        assertThat(e.getMessage(), containsString("cannot delete - another snapshot is currently being deleted"));
    }
    logger.info("--> unblocking blocked node [{}]", blockedNode);
    unblockNode("repo", blockedNode);
    logger.info("--> wait until second snapshot deletion is finished");
    assertAcked(future.actionGet());
    logger.info("--> try delete first snapshot again, which should now work");
    execute("drop snapshot repo.snapshot1");
    assertTrue(client().admin().cluster().prepareGetSnapshots("repo").setSnapshots("_all").get().getSnapshots().isEmpty());
}
Also used : MockRepository(org.elasticsearch.snapshots.mockstore.MockRepository) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 40 with AcknowledgedResponse

use of org.elasticsearch.action.support.master.AcknowledgedResponse in project graylog2-server by Graylog2.

the class V20200730000000_AddGl2MessageIdFieldAliasForEventsES7 method addGl2MessageIdFieldAlias.

@Override
public void addGl2MessageIdFieldAlias(Set<String> indexPrefixes) {
    final String[] prefixesWithWildcard = indexPrefixes.stream().map(p -> p + "*").toArray(String[]::new);
    final PutMappingRequest putMappingRequest = new PutMappingRequest(prefixesWithWildcard).indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED).source(ImmutableMap.of("properties", ImmutableMap.of(FIELD_GL2_MESSAGE_ID, aliasMapping())));
    try {
        final AcknowledgedResponse acknowledgedResponse = client.execute((c, requestOptions) -> c.indices().putMapping(putMappingRequest, requestOptions));
        if (!acknowledgedResponse.isAcknowledged()) {
            throw new ElasticsearchException(errorMsgFor(prefixesWithWildcard) + " Elasticsearch failed to acknowledge.");
        }
    } catch (ElasticsearchException e) {
        throw new ElasticsearchException(errorMsgFor(prefixesWithWildcard), e);
    }
}
Also used : Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) V20200730000000_AddGl2MessageIdFieldAliasForEvents(org.graylog.plugins.views.migrations.V20200730000000_AddGl2MessageIdFieldAliasForEvents) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Arrays(java.util.Arrays) ImmutableMap(com.google.common.collect.ImmutableMap) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) Set(java.util.Set) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) FIELD_GL2_MESSAGE_ID(org.graylog2.plugin.Message.FIELD_GL2_MESSAGE_ID) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) ElasticsearchException(org.graylog2.indexer.ElasticsearchException)

Aggregations

AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)37 IOException (java.io.IOException)11 FutureActionListener (io.crate.action.FutureActionListener)9 ClusterState (org.elasticsearch.cluster.ClusterState)7 Row1 (io.crate.data.Row1)6 Map (java.util.Map)6 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)6 Metadata (org.elasticsearch.cluster.metadata.Metadata)6 Row (io.crate.data.Row)5 RelationName (io.crate.metadata.RelationName)5 Arrays (java.util.Arrays)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Reference (io.crate.metadata.Reference)4 DataType (io.crate.types.DataType)4 ArrayList (java.util.ArrayList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 StreamSupport (java.util.stream.StreamSupport)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4