@Override public Policy get(String resourceId) { try { ThrottlingPolicy throttlingPolicy = (ThrottlingPolicy) this.broker.getSharedResource(new ThrottlingPolicyFactory(), new SharedLimiterKey(resourceId)); Policy restliPolicy = new Policy(); restliPolicy.setPolicyName(throttlingPolicy.getClass().getSimpleName()); restliPolicy.setResource(resourceId); restliPolicy.setParameters(new StringMap(throttlingPolicy.getParameters())); restliPolicy.setPolicyDetails(throttlingPolicy.getDescription()); MetricContext resourceContext = (MetricContext) broker.getSharedResource(new MetricContextFactory(), new SubTaggedMetricContextKey(resourceId, ImmutableMap.of(RESOURCE_ID_TAG, resourceId))); StringMap metrics = new StringMap(); for (Map.Entry<String, Meter> meter : resourceContext.getMeters().entrySet()) { metrics.put(meter.getKey(), Double.toString(meter.getValue().getOneMinuteRate())); } restliPolicy.setMetrics(metrics); return restliPolicy; } catch (NotConfiguredException nce) { throw new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Policy not found for resource " + resourceId); } } }
@Override public Policy get(String resourceId) { try { ThrottlingPolicy throttlingPolicy = (ThrottlingPolicy) this.broker.getSharedResource(new ThrottlingPolicyFactory(), new SharedLimiterKey(resourceId)); Policy restliPolicy = new Policy(); restliPolicy.setPolicyName(throttlingPolicy.getClass().getSimpleName()); restliPolicy.setResource(resourceId); restliPolicy.setParameters(new StringMap(throttlingPolicy.getParameters())); restliPolicy.setPolicyDetails(throttlingPolicy.getDescription()); MetricContext resourceContext = (MetricContext) broker.getSharedResource(new MetricContextFactory(), new SubTaggedMetricContextKey(resourceId, ImmutableMap.of(RESOURCE_ID_TAG, resourceId))); StringMap metrics = new StringMap(); for (Map.Entry<String, Meter> meter : resourceContext.getMeters().entrySet()) { metrics.put(meter.getKey(), Double.toString(meter.getValue().getOneMinuteRate())); } restliPolicy.setMetrics(metrics); return restliPolicy; } catch (NotConfiguredException nce) { throw new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "Policy not found for resource " + resourceId); } } }