refactor(gateway-policies): separate transfer quota probe response
MODIFY
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/TransferQuotaPolicy.java
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/TransferQuotaPolicy.java
@@ -34,7 +34,7 @@ import io.apiman.gateway.engine.policies.config.TransferQuotaConfig;
import io.apiman.gateway.engine.policies.i18n.Messages;
import io.apiman.gateway.engine.policies.limiting.BucketFactory;
import io.apiman.gateway.engine.policies.probe.RateLimitingProbeConfig;
-import io.apiman.gateway.engine.policies.probe.RateLimitingProbeResponse;
+import io.apiman.gateway.engine.policies.probe.TransferQuotaProbeResponse;
import io.apiman.gateway.engine.policy.IPolicyChain;
import io.apiman.gateway.engine.policy.IPolicyContext;
import io.apiman.gateway.engine.policy.IPolicyProbe;
@@ -68,11 +68,6 @@ public class TransferQuotaPolicy extends AbstractMappedDataPolicy<TransferQuotaC
public TransferQuotaPolicy() {
}
- @Override
- public Class<RateLimitingProbeConfig> getProbeRequestClass() {
- return RateLimitingProbeConfig.class;
- }
-
@Override
public Class<TransferQuotaConfig> getConfigurationClass() {
return TransferQuotaConfig.class;
@@ -86,21 +81,6 @@ public class TransferQuotaPolicy extends AbstractMappedDataPolicy<TransferQuotaC
return "XFERQUOTA||" + bucketFactory.bucketId(request, probeContext, config);
}
- @Override
- public void probe(RateLimitingProbeConfig probeRequest, TransferQuotaConfig policyConfig, ProbeContext probeContext, IPolicyContext context,
- IAsyncResultHandler<IPolicyProbeResponse> resultHandler) {
- String bucketId = bucketId(probeRequest, probeContext, policyConfig);
- IRateLimiterComponent rateLimiter = context.getComponent(IRateLimiterComponent.class);
- // Ask for rate limit, but don't actually decrement the counter.
- rateLimiter.accept(bucketId, bucketFactory.getPeriod(policyConfig), policyConfig.getLimit(), 0, rateLimResult -> {
- RateLimitResponse remaining = rateLimResult.getResult();
- var probeResult = new RateLimitingProbeResponse()
- .setStatus(remaining)
- .setConfig(policyConfig);
- resultHandler.handle(AsyncResultImpl.create(probeResult));
- });
- }
-
@Override
protected void doApply(final ApiRequest request, final IPolicyContext context, final TransferQuotaConfig config,
final IPolicyChain<ApiRequest> chain) {
@@ -320,4 +300,25 @@ public class TransferQuotaPolicy extends AbstractMappedDataPolicy<TransferQuotaC
protected String defaultLimitHeader() {
return DEFAULT_LIMIT_HEADER;
}
+
+
+ @Override
+ public Class<RateLimitingProbeConfig> getProbeRequestClass() {
+ return RateLimitingProbeConfig.class;
+ }
+
+ @Override
+ public void probe(RateLimitingProbeConfig probeRequest, TransferQuotaConfig policyConfig, ProbeContext probeContext, IPolicyContext context,
+ IAsyncResultHandler<IPolicyProbeResponse> resultHandler) {
+ String bucketId = bucketId(probeRequest, probeContext, policyConfig);
+ IRateLimiterComponent rateLimiter = context.getComponent(IRateLimiterComponent.class);
+ // Ask for rate limit, but don't actually decrement the counter.
+ rateLimiter.accept(bucketId, bucketFactory.getPeriod(policyConfig), policyConfig.getLimit(), 0, rateLimResult -> {
+ RateLimitResponse remaining = rateLimResult.getResult();
+ var probeResult = new TransferQuotaProbeResponse()
+ .setStatus(remaining)
+ .setConfig(policyConfig);
+ resultHandler.handle(AsyncResultImpl.create(probeResult));
+ });
+ }
}

MODIFY
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/probe/ProbeRegistry.java
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/probe/ProbeRegistry.java
@@ -23,6 +23,7 @@ public class ProbeRegistry {
static {
register(RateLimitingProbeResponse.class);
+ register(TransferQuotaProbeResponse.class);
}
public static void register(Class<? extends IPolicyProbeResponse> response) {

ADD
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/probe/TransferQuotaProbeResponse.java
+package io.apiman.gateway.engine.policies.probe;
+
+import io.apiman.gateway.engine.beans.IPolicyProbeResponse;
+import io.apiman.gateway.engine.components.rate.RateLimitResponse;
+import io.apiman.gateway.engine.policies.config.TransferQuotaConfig;
+
+/**
+ *
+ *
+ * @author Marc Savy {@literal <marc@blackparrotlabs.io>}
+ */
+public class TransferQuotaProbeResponse implements IPolicyProbeResponse {
+
+ private String probeType = "TransferQuotaProbeResponse";
+ private TransferQuotaConfig config;
+ private RateLimitResponse status;
+
+ public TransferQuotaProbeResponse() {
+ }
+
+ public TransferQuotaConfig getConfig() {
+ return config;
+ }
+
+ public TransferQuotaProbeResponse setConfig(TransferQuotaConfig config) {
+ this.config = config;
+ return this;
+ }
+
+ public RateLimitResponse getStatus() {
+ return status;
+ }
+
+ public TransferQuotaProbeResponse setStatus(RateLimitResponse status) {
+ this.status = status;
+ return this;
+ }
+
+ @Override
+ public String getProbeType() {
+ return probeType;
+ }
+}

refactor(gateway-policies): separate transfer quota probe response