use of org.graylog.shaded.elasticsearch7.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);
}
});
}
}
use of org.graylog.shaded.elasticsearch7.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();
}
}
use of org.graylog.shaded.elasticsearch7.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));
}
use of org.graylog.shaded.elasticsearch7.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());
}
use of org.graylog.shaded.elasticsearch7.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);
}
}
Aggregations