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

org.elasticsearch.protocol.xpack.XPackUsageResponse Maven / Gradle / Ivy

/*
 * 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; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */
package org.elasticsearch.protocol.xpack;

import org.elasticsearch.common.xcontent.XContentParser;

import java.io.IOException;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Response object from calling the xpack usage api.
 *
 * Usage information for each feature is accessible through {@link #getUsages()}.
 */
public class XPackUsageResponse {

    private final Map> usages;

    private XPackUsageResponse(Map> usages) throws IOException {
        this.usages = usages;
    }

    @SuppressWarnings("unchecked")
    private static Map castMap(Object value) {
        return (Map)value;
    }

    /** Return a map from feature name to usage information for that feature. */
    public Map> getUsages() {
        return usages;
    }

    public static XPackUsageResponse fromXContent(XContentParser parser) throws IOException {
        Map rawMap = parser.map();
        Map> usages = rawMap.entrySet().stream().collect(
            Collectors.toMap(Map.Entry::getKey, e -> castMap(e.getValue())));
        return new XPackUsageResponse(usages);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy