Search in sources :

Example 1 with ShardResult

use of org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult in project fesen-httpclient by codelibs.

the class HttpCloseIndexAction method parseIndexResult.

protected IndexResult parseIndexResult(final XContentParser parser, final String index) throws IOException {
    boolean closed = false;
    OpenSearchException eex = null;
    final List<ShardResult> shardResults = new ArrayList<>();
    String fieldName = null;
    XContentParser.Token token;
    while ((token = parser.currentToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            fieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            if ("exception".equals(fieldName)) {
                parser.nextToken();
                eex = OpenSearchException.fromXContent(parser);
            } else if ("failedShards".equals(fieldName)) {
                parser.nextToken();
                shardResults.addAll(parseShardResults(parser));
            }
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("closed".equals(fieldName)) {
                closed = parser.booleanValue();
            }
        }
        parser.nextToken();
    }
    final Index idx = new Index(index, "unknown");
    if (closed) {
        return new IndexResult(idx);
    }
    if (eex != null) {
        return new IndexResult(idx, eex);
    }
    if (!shardResults.isEmpty()) {
        return new IndexResult(idx, shardResults.toArray(new ShardResult[shardResults.size()]));
    }
    return new IndexResult(idx);
}
Also used : ArrayList(java.util.ArrayList) IndexResult(org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult) OpenSearchException(org.opensearch.OpenSearchException) ShardResult(org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult) Index(org.opensearch.index.Index) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

ArrayList (java.util.ArrayList)1 OpenSearchException (org.opensearch.OpenSearchException)1 IndexResult (org.opensearch.action.admin.indices.close.CloseIndexResponse.IndexResult)1 ShardResult (org.opensearch.action.admin.indices.close.CloseIndexResponse.ShardResult)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 Index (org.opensearch.index.Index)1