Search in sources :

Example 1 with HalfOpenConfig

use of com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig in project polaris-java by polarismesh.

the class ConsecutiveCircuitBreaker method init.

@Override
public void init(InitContext ctx) throws PolarisException {
    CircuitBreakerConfig circuitBreakerConfig = ctx.getConfig().getConsumer().getCircuitBreaker();
    OutlierDetectionConfig outlierDetection = ctx.getConfig().getConsumer().getOutlierDetection();
    HalfOpenConfig halfOpenConfig = new HalfOpenConfig(circuitBreakerConfig, outlierDetection);
    Config cfg = circuitBreakerConfig.getPluginConfig(getName(), Config.class);
    if (cfg == null) {
        throw new PolarisException(ErrorCode.INVALID_CONFIG, String.format("plugin %s config is missing", getName()));
    }
    ConfigSet<Config> configSet = new ConfigSet<>(StatusDimension.Level.SERVICE, false, halfOpenConfig, cfg);
    configGroup = new ConfigGroup<>(configSet);
    stateMachine = new StateMachineImpl(configGroup, id, this);
    flowControlParam = new DefaultFlowControlParam(ctx.getConfig().getGlobal().getAPI());
}
Also used : PolarisException(com.tencent.polaris.api.exception.PolarisException) OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) DefaultFlowControlParam(com.tencent.polaris.client.flow.DefaultFlowControlParam) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) ConsecutiveErrConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ConsecutiveErrConfig) OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) RecoverConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.RecoverConfig) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) ConfigSet(com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet)

Example 2 with HalfOpenConfig

use of com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig in project polaris-java by polarismesh.

the class ErrRateCircuitBreaker method init.

@Override
public void init(InitContext ctx) throws PolarisException {
    CircuitBreakerConfig circuitBreakerConfig = ctx.getConfig().getConsumer().getCircuitBreaker();
    OutlierDetectionConfig outlierDetection = ctx.getConfig().getConsumer().getOutlierDetection();
    metricWindowMs = circuitBreakerConfig.getCheckPeriod();
    HalfOpenConfig halfOpenConfig = new HalfOpenConfig(circuitBreakerConfig, outlierDetection);
    Config cfg = circuitBreakerConfig.getPluginConfig(getName(), Config.class);
    if (cfg == null) {
        throw new PolarisException(ErrorCode.INVALID_CONFIG, String.format("plugin %s config is missing", getName()));
    }
    ConfigSet<Config> configSet = new ConfigSet<>(StatusDimension.Level.SERVICE, false, halfOpenConfig, cfg);
    create = new Function<Integer, Object>() {

        @Override
        public Object apply(Integer integer) {
            return new ErrRateCounter(metricWindowName, configSet.getPlugConfig(), getBucketIntervalMs());
        }
    };
    configGroup = new ConfigGroup<>(configSet);
    stateMachine = new StateMachineImpl(configGroup, id, this, metricWindowMs);
    flowControlParam = new DefaultFlowControlParam(ctx.getConfig().getGlobal().getAPI());
}
Also used : OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) OutlierDetectionConfig(com.tencent.polaris.api.config.consumer.OutlierDetectionConfig) RecoverConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.RecoverConfig) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) ErrRateConfig(com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ErrRateConfig) HalfOpenConfig(com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig) PolarisException(com.tencent.polaris.api.exception.PolarisException) DefaultFlowControlParam(com.tencent.polaris.client.flow.DefaultFlowControlParam) CircuitBreakerConfig(com.tencent.polaris.api.config.consumer.CircuitBreakerConfig) ConfigSet(com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet)

Aggregations

CircuitBreakerConfig (com.tencent.polaris.api.config.consumer.CircuitBreakerConfig)2 OutlierDetectionConfig (com.tencent.polaris.api.config.consumer.OutlierDetectionConfig)2 PolarisException (com.tencent.polaris.api.exception.PolarisException)2 DefaultFlowControlParam (com.tencent.polaris.client.flow.DefaultFlowControlParam)2 RecoverConfig (com.tencent.polaris.client.pb.CircuitBreakerProto.RecoverConfig)2 ConfigSet (com.tencent.polaris.plugins.circuitbreaker.common.ConfigSet)2 HalfOpenConfig (com.tencent.polaris.plugins.circuitbreaker.common.HalfOpenConfig)2 ConsecutiveErrConfig (com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ConsecutiveErrConfig)1 ErrRateConfig (com.tencent.polaris.client.pb.CircuitBreakerProto.CbPolicy.ErrRateConfig)1