Search in sources :

Example 1 with ClusterAllocationExplainResponse

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);
        }
    });
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) ToXContent(org.opensearch.common.xcontent.ToXContent) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ClusterAllocationExplainRequest(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest) ClusterAllocationExplainResponse(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse) BaseRestHandler(org.opensearch.rest.BaseRestHandler) ClusterAllocationExplainRequest(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest) ClusterAllocationExplainResponse(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) BytesRestResponse(org.opensearch.rest.BytesRestResponse) IOException(java.io.IOException) XContentParser(org.opensearch.common.xcontent.XContentParser) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 2 with ClusterAllocationExplainResponse

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"));
}
Also used : IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) Path(java.nio.file.Path) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) ClusterAllocationExplainResponse(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) InternalTestCluster(org.opensearch.test.InternalTestCluster) TranslogCorruptedException(org.opensearch.index.translog.TranslogCorruptedException) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException)

Aggregations

ClusterAllocationExplainResponse (org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 List (java.util.List)1 ClusterAllocationExplainRequest (org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest)1 IndexRequestBuilder (org.opensearch.action.index.IndexRequestBuilder)1 SearchPhaseExecutionException (org.opensearch.action.search.SearchPhaseExecutionException)1 NodeClient (org.opensearch.client.node.NodeClient)1 UnassignedInfo (org.opensearch.cluster.routing.UnassignedInfo)1 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)1 ToXContent (org.opensearch.common.xcontent.ToXContent)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 TranslogCorruptedException (org.opensearch.index.translog.TranslogCorruptedException)1 BaseRestHandler (org.opensearch.rest.BaseRestHandler)1 BytesRestResponse (org.opensearch.rest.BytesRestResponse)1 RestRequest (org.opensearch.rest.RestRequest)1 GET (org.opensearch.rest.RestRequest.Method.GET)1