Search in sources :

Example 1 with ApiMetricCostConfig

use of com.google.api.server.spi.config.model.ApiMetricCostConfig in project endpoints-java by cloudendpoints.

the class ApiMethodAnnotationConfig method setMetricCosts.

public void setMetricCosts(ApiMetricCost[] metricCosts) {
    ImmutableList.Builder<ApiMetricCostConfig> costs = ImmutableList.builder();
    if (metricCosts != null && metricCosts.length > 0) {
        for (ApiMetricCost cost : metricCosts) {
            costs.add(ApiMetricCostConfig.builder().setName(cost.name()).setCost(cost.cost()).build());
        }
    }
    config.setMetricCosts(costs.build());
}
Also used : ApiMetricCostConfig(com.google.api.server.spi.config.model.ApiMetricCostConfig) ImmutableList(com.google.common.collect.ImmutableList) ApiMetricCost(com.google.api.server.spi.config.ApiMetricCost)

Example 2 with ApiMetricCostConfig

use of com.google.api.server.spi.config.model.ApiMetricCostConfig in project endpoints-java by cloudendpoints.

the class SwaggerGenerator method addDefinedMetricCosts.

private void addDefinedMetricCosts(Map<String, ApiLimitMetricConfig> limitMetrics, Operation operation, List<ApiMetricCostConfig> metricCosts) throws ApiConfigException {
    if (!metricCosts.isEmpty()) {
        Map<String, Integer> costs = new HashMap<>();
        for (ApiMetricCostConfig cost : metricCosts) {
            if (!limitMetrics.containsKey(cost.name())) {
                throw new ApiConfigException(String.format("Could not add a metric cost for metric '%s'. The limit metric must be " + "defined at the API level.", cost.name()));
            }
            costs.put(cost.name(), cost.cost());
        }
        operation.setVendorExtension("x-google-quota", ImmutableMap.of("metricCosts", costs));
    }
}
Also used : ApiMetricCostConfig(com.google.api.server.spi.config.model.ApiMetricCostConfig) ApiConfigException(com.google.api.server.spi.config.ApiConfigException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ApiMetricCostConfig (com.google.api.server.spi.config.model.ApiMetricCostConfig)2 ApiConfigException (com.google.api.server.spi.config.ApiConfigException)1 ApiMetricCost (com.google.api.server.spi.config.ApiMetricCost)1 ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1