All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opensearch.repositories.RepositoriesStats Maven / Gradle / Ivy

There is a newer version: 2.18.0
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 */

package org.opensearch.repositories;

import org.opensearch.common.annotation.PublicApi;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;
import org.opensearch.core.common.util.CollectionUtils;
import org.opensearch.core.xcontent.ToXContentObject;
import org.opensearch.core.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.List;

/**
 * Encapsulates stats for multiple repositories
 *
 * @opensearch.api
 */
@PublicApi(since = "2.11.0")
public class RepositoriesStats implements Writeable, ToXContentObject {

    List repositoryStatsSnapshots;

    public RepositoriesStats(List repositoryStatsSnapshots) {
        this.repositoryStatsSnapshots = repositoryStatsSnapshots;
    }

    public RepositoriesStats(StreamInput in) throws IOException {
        this.repositoryStatsSnapshots = in.readList(RepositoryStatsSnapshot::new);
    }

    @Override
    public void writeTo(StreamOutput out) throws IOException {
        out.writeList(repositoryStatsSnapshots);
    }

    @Override
    public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
        builder.startArray("repositories");
        if (CollectionUtils.isEmpty(repositoryStatsSnapshots) == false) {
            for (RepositoryStatsSnapshot repositoryStatsSnapshot : repositoryStatsSnapshots) {
                repositoryStatsSnapshot.toXContent(builder, params);
            }
        }
        builder.endArray();
        return builder;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy