Line data Source code
1 : // Copyright (C) 2015 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.metrics.dropwizard; 16 : 17 : import com.google.gerrit.extensions.restapi.AuthException; 18 : import com.google.gerrit.extensions.restapi.Response; 19 : import com.google.gerrit.extensions.restapi.RestReadView; 20 : import com.google.gerrit.server.permissions.GlobalPermission; 21 : import com.google.gerrit.server.permissions.PermissionBackend; 22 : import com.google.gerrit.server.permissions.PermissionBackendException; 23 : import com.google.inject.Inject; 24 : import org.kohsuke.args4j.Option; 25 : 26 : class GetMetric implements RestReadView<MetricResource> { 27 : private final PermissionBackend permissionBackend; 28 : private final DropWizardMetricMaker metrics; 29 : 30 : @Option(name = "--data-only", usage = "return only values") 31 : boolean dataOnly; 32 : 33 : @Inject 34 0 : GetMetric(PermissionBackend permissionBackend, DropWizardMetricMaker metrics) { 35 0 : this.permissionBackend = permissionBackend; 36 0 : this.metrics = metrics; 37 0 : } 38 : 39 : @Override 40 : public Response<MetricJson> apply(MetricResource resource) 41 : throws AuthException, PermissionBackendException { 42 0 : permissionBackend.currentUser().check(GlobalPermission.VIEW_CACHES); 43 0 : return Response.ok( 44 0 : new MetricJson(resource.getMetric(), metrics.getAnnotations(resource.getName()), dataOnly)); 45 : } 46 : }