use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testValidateQuery.
@SuppressWarnings("unused")
public void testValidateQuery() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();
String index = "some_index";
createIndex(index, Settings.EMPTY);
// tag::indices-validate-query-request
// <1>
ValidateQueryRequest request = new ValidateQueryRequest(index);
// end::indices-validate-query-request
// tag::indices-validate-query-request-query
QueryBuilder builder = QueryBuilders.boolQuery().must(QueryBuilders.queryStringQuery("*:*")).filter(QueryBuilders.termQuery("user", "foobar"));
// <2>
request.query(builder);
// end::indices-validate-query-request-query
// tag::indices-validate-query-request-explain
// <1>
request.explain(true);
// end::indices-validate-query-request-explain
// tag::indices-validate-query-request-allShards
// <1>
request.allShards(true);
// end::indices-validate-query-request-allShards
// tag::indices-validate-query-request-rewrite
// <1>
request.rewrite(true);
// end::indices-validate-query-request-rewrite
// tag::indices-validate-query-execute
// <1>
ValidateQueryResponse response = client.indices().validateQuery(request, RequestOptions.DEFAULT);
// end::indices-validate-query-execute
// tag::indices-validate-query-response
// <1>
boolean isValid = response.isValid();
// <2>
int totalShards = response.getTotalShards();
// <3>
int successfulShards = response.getSuccessfulShards();
// <4>
int failedShards = response.getFailedShards();
if (failedShards > 0) {
for (DefaultShardOperationFailedException failure : response.getShardFailures()) {
// <5>
// <6>
String failedIndex = failure.index();
// <7>
int shardId = failure.shardId();
// <8>
String reason = failure.reason();
}
}
for (QueryExplanation explanation : response.getQueryExplanation()) {
// <9>
// <10>
String explanationIndex = explanation.getIndex();
// <11>
int shardId = explanation.getShard();
// <12>
String explanationString = explanation.getExplanation();
}
// end::indices-validate-query-response
// tag::indices-validate-query-execute-listener
ActionListener<ValidateQueryResponse> listener = new ActionListener<ValidateQueryResponse>() {
@Override
public void onResponse(ValidateQueryResponse validateQueryResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::indices-validate-query-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::indices-validate-query-execute-async
// <1>
client.indices().validateQueryAsync(request, RequestOptions.DEFAULT, listener);
// end::indices-validate-query-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.
the class BroadcastResponseTests method assertInstances.
@Override
protected void assertInstances(org.opensearch.action.support.broadcast.BroadcastResponse serverTestInstance, BroadcastResponse clientInstance) {
assertThat(clientInstance.shards().total(), equalTo(serverTestInstance.getTotalShards()));
assertThat(clientInstance.shards().successful(), equalTo(serverTestInstance.getSuccessfulShards()));
assertThat(clientInstance.shards().skipped(), equalTo(0));
assertThat(clientInstance.shards().failed(), equalTo(serverTestInstance.getFailedShards()));
// failures are grouped
assertThat(clientInstance.shards().failures(), hasSize(clientInstance.shards().failed() == 0 ? 0 : 1));
if (clientInstance.shards().failed() > 0) {
final DefaultShardOperationFailedException groupedFailure = clientInstance.shards().failures().iterator().next();
assertThat(groupedFailure.index(), equalTo(index));
assertThat(groupedFailure.shardId(), in(shardIds));
assertThat(groupedFailure.reason(), containsString("reason=retention lease with ID [" + id + "] not found"));
}
}
use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.
the class BroadcastResponseTests method createServerTestInstance.
@Override
protected org.opensearch.action.support.broadcast.BroadcastResponse createServerTestInstance(XContentType xContentType) {
index = randomAlphaOfLength(8);
id = randomAlphaOfLength(8);
final int total = randomIntBetween(1, 16);
final int successful = total - scaledRandomIntBetween(0, total);
final int failed = scaledRandomIntBetween(0, total - successful);
final List<DefaultShardOperationFailedException> failures = new ArrayList<>();
shardIds = new HashSet<>();
for (int i = 0; i < failed; i++) {
final DefaultShardOperationFailedException failure = new DefaultShardOperationFailedException(index, randomValueOtherThanMany(shardIds::contains, () -> randomIntBetween(0, total - 1)), new RetentionLeaseNotFoundException(id));
failures.add(failure);
shardIds.add(failure.shardId());
}
return new org.opensearch.action.support.broadcast.BroadcastResponse(total, successful, failed, failures);
}
use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.
the class DataStreamsStatsResponseTests method createServerTestInstance.
@Override
protected DataStreamsStatsAction.Response createServerTestInstance(XContentType xContentType) {
int dataStreamCount = randomInt(10);
int backingIndicesTotal = 0;
long totalStoreSize = 0L;
ArrayList<DataStreamsStatsAction.DataStreamStats> dataStreamStats = new ArrayList<>();
for (int i = 0; i < dataStreamCount; i++) {
String dataStreamName = randomAlphaOfLength(8).toLowerCase(Locale.getDefault());
int backingIndices = randomInt(5);
backingIndicesTotal += backingIndices;
long storeSize = randomLongBetween(250, 1000000000);
totalStoreSize += storeSize;
long maximumTimestamp = randomRecentTimestamp();
dataStreamStats.add(new DataStreamsStatsAction.DataStreamStats(dataStreamName, backingIndices, new ByteSizeValue(storeSize), maximumTimestamp));
}
int totalShards = randomIntBetween(backingIndicesTotal, backingIndicesTotal * 3);
int successfulShards = randomInt(totalShards);
int failedShards = totalShards - successfulShards;
List<DefaultShardOperationFailedException> exceptions = new ArrayList<>();
for (int i = 0; i < failedShards; i++) {
exceptions.add(new DefaultShardOperationFailedException(randomAlphaOfLength(8).toLowerCase(Locale.getDefault()), randomInt(totalShards), new OpenSearchException("boom")));
}
return new DataStreamsStatsAction.Response(totalShards, successfulShards, failedShards, exceptions, dataStreamCount, backingIndicesTotal, new ByteSizeValue(totalStoreSize), dataStreamStats.toArray(new DataStreamsStatsAction.DataStreamStats[0]));
}
use of org.opensearch.action.support.DefaultShardOperationFailedException in project OpenSearch by opensearch-project.
the class BroadcastResponse method writeTo.
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(totalShards);
out.writeVInt(successfulShards);
out.writeVInt(failedShards);
out.writeVInt(shardFailures.length);
for (DefaultShardOperationFailedException exp : shardFailures) {
exp.writeTo(out);
}
}
Aggregations