Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
mageddo committed Oct 21, 2024
1 parent e638f9f commit a690dfa
Showing 1 changed file with 11 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.mageddo.dnsproxyserver.config.dataprovider.mapper;

import com.mageddo.dnsproxyserver.config.CanaryRateThresholdCircuitBreakerStrategyConfig;
import com.mageddo.dnsproxyserver.config.CircuitBreakerStrategyConfig;
import com.mageddo.dnsproxyserver.config.StaticThresholdCircuitBreakerStrategyConfig;
import com.mageddo.dnsproxyserver.config.Config;
import com.mageddo.dnsproxyserver.config.SolverRemote;
import com.mageddo.dnsproxyserver.config.StaticThresholdCircuitBreakerStrategyConfig;
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJson;
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJsonV2;
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJsonV2.CanaryRateThresholdCircuitBreaker;
import com.mageddo.dnsproxyserver.config.dataprovider.vo.ConfigJsonV2.StaticThresholdCircuitBreaker;
import com.mageddo.dnsproxyserver.utils.Booleans;
import org.apache.commons.lang3.ObjectUtils;

Expand Down Expand Up @@ -68,35 +64,16 @@ static SolverRemote buildCompleteSolverRemote(ConfigJson json, ConfigJsonV2.Circ
return SolverRemote
.builder()
.active(Booleans.reverseWhenNotNull(json.getNoRemoteServers()))
.circuitBreaker(mapCircuitBreaker(circuitBreaker))
.build();
}

private static CircuitBreakerStrategyConfig mapCircuitBreaker(ConfigJsonV2.CircuitBreaker circuitBreaker) {
return switch (circuitBreaker.strategy()){
case STATIC_THRESHOLD -> mapFromStaticCircuitBreaker((StaticThresholdCircuitBreaker) circuitBreaker);
case CANARY_RATE_THRESHOLD -> mapFromCanaryRateThresholdCircuitBreaker((CanaryRateThresholdCircuitBreaker) circuitBreaker);
default -> throw new UnsupportedOperationException("Unrecognized circuit breaker: " + circuitBreaker.strategy());
};
}

private static CircuitBreakerStrategyConfig mapFromCanaryRateThresholdCircuitBreaker(
CanaryRateThresholdCircuitBreaker circuitBreaker
) {
return CanaryRateThresholdCircuitBreakerStrategyConfig.builder()
.failureRateThreshold(circuitBreaker.getFailureRateThreshold())
.minimumNumberOfCalls(circuitBreaker.getMinimumNumberOfCalls())
.permittedNumberOfCallsInHalfOpenState(circuitBreaker.getPermittedNumberOfCallsInHalfOpenState())
.build();
}

private static CircuitBreakerStrategyConfig mapFromStaticCircuitBreaker(StaticThresholdCircuitBreaker circuitBreaker) {
return StaticThresholdCircuitBreakerStrategyConfig
.builder()
.failureThreshold(circuitBreaker.getFailureThreshold())
.failureThresholdCapacity(circuitBreaker.getFailureThresholdCapacity())
.successThreshold(circuitBreaker.getSuccessThreshold())
.testDelay(circuitBreaker.getTestDelay())
// fixme #533 need to create a dynamic json parser for different strategies,
// then a dynamic mapper to the solver remote
.circuitBreaker(StaticThresholdCircuitBreakerStrategyConfig
.builder()
.failureThreshold(circuitBreaker.getFailureThreshold())
.failureThresholdCapacity(circuitBreaker.getFailureThresholdCapacity())
.successThreshold(circuitBreaker.getSuccessThreshold())
.testDelay(circuitBreaker.getTestDelay())
.build()
)
.build();
}
}

0 comments on commit a690dfa

Please sign in to comment.