Search in sources :

Example 1 with DynamicProperty

use of com.netflix.config.DynamicProperty in project incubator-servicecomb-java-chassis by apache.

the class QpsControllerManager method setGlobalQpsController.

public QpsControllerManager setGlobalQpsController(String globalConfigKey) {
    DynamicProperty globalQpsProperty = DynamicProperty.getInstance(globalConfigKey);
    QpsController qpsController = new QpsController(globalConfigKey, globalQpsProperty.getInteger());
    globalQpsProperty.addCallback(() -> {
        qpsController.setQpsLimit(globalQpsProperty.getInteger());
        LOGGER.info("Global qps limit update, value = [{}]", globalQpsProperty.getInteger());
    });
    this.globalQpsController = qpsController;
    return this;
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty)

Example 2 with DynamicProperty

use of com.netflix.config.DynamicProperty in project incubator-servicecomb-java-chassis by apache.

the class QpsControllerManager method createQpsControllerIfNotExist.

private void createQpsControllerIfNotExist(String configKey) {
    if (configQpsControllerMap.keySet().contains(configKey)) {
        return;
    }
    LOGGER.info("Create qpsController, configKey = [{}]", configKey);
    DynamicProperty property = getDynamicProperty(configKey);
    QpsController qpsController = new QpsController(configKey, property.getInteger());
    configQpsControllerMap.put(configKey, qpsController);
    property.addCallback(() -> {
        qpsController.setQpsLimit(property.getInteger());
        LOGGER.info("Qps limit updated, configKey = [{}], value = [{}]", configKey, property.getString());
        updateObjMap(configKey);
    });
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty)

Example 3 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class PriorityProperty method doUpdateFinalValue.

/**
 * @return if value changed, return effectiveKey, otherwise null
 */
private String doUpdateFinalValue() {
    T lastValue = finalValue;
    String effectiveKey = "default value";
    T value = propertyType.getDefaultValue();
    for (DynamicProperty property : properties) {
        T propValue = internalValueReader.apply(property);
        if (propValue == null || propValue.equals(propertyType.getInvalidValue())) {
            continue;
        }
        effectiveKey = property.getName();
        value = propValue;
        break;
    }
    if (Objects.equals(lastValue, value)) {
        return null;
    }
    finalValue = value;
    return effectiveKey;
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty)

Example 4 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class QpsControllerManager method createQpsControllerIfNotExist.

private void createQpsControllerIfNotExist(String configKey) {
    if (configQpsControllerMap.containsKey(configKey)) {
        return;
    }
    LOGGER.info("Create qpsController, configKey = [{}]", configKey);
    DynamicProperty limitProperty = DynamicProperty.getInstance(limitKeyPrefix + configKey);
    DynamicProperty bucketProperty = DynamicProperty.getInstance(bucketKeyPrefix + configKey);
    DynamicProperty strategyProperty = DynamicProperty.getInstance(Config.STRATEGY_KEY);
    AbstractQpsStrategy qpsStrategy = chooseStrategy(configKey, limitProperty.getLong(), bucketProperty.getLong(), strategyProperty.getString());
    strategyProperty.addCallback(() -> {
        AbstractQpsStrategy innerQpsStrategy = chooseStrategy(configKey, limitProperty.getLong(), bucketProperty.getLong(), strategyProperty.getString());
        configQpsControllerMap.put(configKey, innerQpsStrategy);
        LOGGER.info("Global flow control strategy update, value = [{}]", strategyProperty.getString());
        updateObjMap(configKey);
    });
    limitProperty.addCallback(() -> {
        qpsStrategy.setQpsLimit(limitProperty.getLong());
        LOGGER.info("Qps limit updated, configKey = [{}], value = [{}]", configKey, limitProperty.getString());
        updateObjMap(configKey);
    });
    bucketProperty.addCallback(() -> {
        qpsStrategy.setBucketLimit(bucketProperty.getLong());
        LOGGER.info("bucket limit updated, configKey = [{}], value = [{}]", configKey, bucketProperty.getString());
        updateObjMap(configKey);
    });
    configQpsControllerMap.put(configKey, qpsStrategy);
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty) AbstractQpsStrategy(org.apache.servicecomb.qps.strategy.AbstractQpsStrategy)

Example 5 with DynamicProperty

use of com.netflix.config.DynamicProperty in project java-chassis by ServiceComb.

the class JaxrsSpringIntegrationTest method testGetConfigFromSpringBoot.

@Test
public void testGetConfigFromSpringBoot() {
    DynamicProperty dynamicProperty = DynamicProperty.getInstance("property.test0");
    assertEquals("from_properties", dynamicProperty.getString());
    dynamicProperty = DynamicProperty.getInstance("property.test1");
    assertEquals("from_yml", dynamicProperty.getString());
    dynamicProperty = DynamicProperty.getInstance("property.test2");
    assertEquals("from_yaml_from_yml", dynamicProperty.getString());
    dynamicProperty = DynamicProperty.getInstance("property.test3");
    assertEquals("from_yaml_dev_from_properties", dynamicProperty.getString());
    dynamicProperty = DynamicProperty.getInstance("property.test4");
    assertEquals("from_microservice_yaml", dynamicProperty.getString());
    dynamicProperty = DynamicProperty.getInstance("property.test5");
    assertEquals("from_system_property", dynamicProperty.getString());
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

DynamicProperty (com.netflix.config.DynamicProperty)11 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 TestConfigObjectFactory (org.apache.servicecomb.config.inject.TestConfigObjectFactory)1 DynamicPropertyView (org.apache.servicecomb.inspector.internal.model.DynamicPropertyView)1 PriorityPropertyView (org.apache.servicecomb.inspector.internal.model.PriorityPropertyView)1 AbstractQpsStrategy (org.apache.servicecomb.qps.strategy.AbstractQpsStrategy)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1