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

org.elasticsearch.client.transform.GetTransformStatsResponse Maven / Gradle / Ivy

There is a newer version: 8.0.0-alpha2
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

package org.elasticsearch.client.transform;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.TaskOperationFailure;
import org.elasticsearch.client.transform.transforms.TransformStats;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.xcontent.ConstructingObjectParser;
import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParser;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;

public class GetTransformStatsResponse {

    public static final ParseField TRANSFORMS = new ParseField("transforms");
    public static final ParseField COUNT = new ParseField("count");

    @SuppressWarnings("unchecked")
    static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(
        "get_transform_stats_response",
        true,
        args -> new GetTransformStatsResponse(
            (List) args[0],
            (long) args[1],
            (List) args[2],
            (List) args[3]
        )
    );

    static {
        PARSER.declareObjectArray(constructorArg(), TransformStats.PARSER::apply, TRANSFORMS);
        PARSER.declareLong(constructorArg(), COUNT);
        PARSER.declareObjectArray(
            optionalConstructorArg(),
            (p, c) -> TaskOperationFailure.fromXContent(p),
            AcknowledgedTasksResponse.TASK_FAILURES
        );
        PARSER.declareObjectArray(
            optionalConstructorArg(),
            (p, c) -> ElasticsearchException.fromXContent(p),
            AcknowledgedTasksResponse.NODE_FAILURES
        );
    }

    public static GetTransformStatsResponse fromXContent(final XContentParser parser) {
        return GetTransformStatsResponse.PARSER.apply(parser, null);
    }

    private final List transformsStats;
    private final long count;
    private final List taskFailures;
    private final List nodeFailures;

    public GetTransformStatsResponse(
        List transformsStats,
        long count,
        @Nullable List taskFailures,
        @Nullable List nodeFailures
    ) {
        this.transformsStats = transformsStats;
        this.count = count;
        this.taskFailures = taskFailures == null ? Collections.emptyList() : Collections.unmodifiableList(taskFailures);
        this.nodeFailures = nodeFailures == null ? Collections.emptyList() : Collections.unmodifiableList(nodeFailures);
    }

    public List getTransformsStats() {
        return transformsStats;
    }

    public long getCount() {
        return count;
    }

    public List getNodeFailures() {
        return nodeFailures;
    }

    public List getTaskFailures() {
        return taskFailures;
    }

    @Override
    public int hashCode() {
        return Objects.hash(transformsStats, count, nodeFailures, taskFailures);
    }

    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }

        if (other == null || getClass() != other.getClass()) {
            return false;
        }

        final GetTransformStatsResponse that = (GetTransformStatsResponse) other;
        return Objects.equals(this.transformsStats, that.transformsStats)
            && Objects.equals(this.count, that.count)
            && Objects.equals(this.nodeFailures, that.nodeFailures)
            && Objects.equals(this.taskFailures, that.taskFailures);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy