use of org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse in project OpenSearch by opensearch-project.
the class RestClusterAllocationExplainAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
ClusterAllocationExplainRequest req;
if (request.hasContentOrSourceParam() == false) {
// Empty request signals "explain the first unassigned shard you find"
req = new ClusterAllocationExplainRequest();
} else {
try (XContentParser parser = request.contentOrSourceParamParser()) {
req = ClusterAllocationExplainRequest.parse(parser);
}
}
req.includeYesDecisions(request.paramAsBoolean("include_yes_decisions", false));
req.includeDiskInfo(request.paramAsBoolean("include_disk_info", false));
return channel -> client.admin().cluster().allocationExplain(req, new RestBuilderListener<ClusterAllocationExplainResponse>(channel) {
@Override
public RestResponse buildResponse(ClusterAllocationExplainResponse response, XContentBuilder builder) throws IOException {
response.getExplanation().toXContent(builder, ToXContent.EMPTY_PARAMS);
return new BytesRestResponse(RestStatus.OK, builder);
}
});
}
use of org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse in project OpenSearch by opensearch-project.
the class CorruptedTranslogIT method testCorruptTranslogFiles.
public void testCorruptTranslogFiles() throws Exception {
internalCluster().startNode(Settings.EMPTY);
assertAcked(prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.refresh_interval", "-1").put(MockEngineSupport.DISABLE_FLUSH_ON_CLOSE.getKey(), // never flush - always recover from translog
true).put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(1, ByteSizeUnit.PB))));
// Index some documents
IndexRequestBuilder[] builders = new IndexRequestBuilder[scaledRandomIntBetween(100, 1000)];
for (int i = 0; i < builders.length; i++) {
builders[i] = client().prepareIndex("test").setSource("foo", "bar");
}
indexRandom(false, false, false, Arrays.asList(builders));
final Path translogPath = internalCluster().getInstance(IndicesService.class).indexService(resolveIndex("test")).getShard(0).shardPath().resolveTranslog();
internalCluster().fullRestart(new InternalTestCluster.RestartCallback() {
@Override
public void onAllNodesStopped() throws Exception {
TestTranslog.corruptRandomTranslogFile(logger, random(), translogPath);
}
});
assertBusy(() -> {
final ClusterAllocationExplainResponse allocationExplainResponse = client().admin().cluster().prepareAllocationExplain().setIndex("test").setShard(0).setPrimary(true).get();
final UnassignedInfo unassignedInfo = allocationExplainResponse.getExplanation().getUnassignedInfo();
assertThat(unassignedInfo, not(nullValue()));
final Throwable cause = ExceptionsHelper.unwrap(unassignedInfo.getFailure(), TranslogCorruptedException.class);
assertThat(cause, not(nullValue()));
assertThat(cause.getMessage(), containsString(translogPath.toString()));
});
assertThat(expectThrows(SearchPhaseExecutionException.class, () -> client().prepareSearch("test").setQuery(matchAllQuery()).get()).getMessage(), containsString("all shards failed"));
}
Aggregations