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());
}
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));
}
}
Aggregations