Search in sources :

Example 6 with DynamicProperty

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

the class QpsControllerManager method initGlobalQpsController.

private void initGlobalQpsController() {
    DynamicProperty globalLimitProperty = DynamicProperty.getInstance(globalLimitKey);
    DynamicProperty globalBucketProperty = DynamicProperty.getInstance(globalBucketKey);
    DynamicProperty globalStrategyProperty = DynamicProperty.getInstance(Config.STRATEGY_KEY);
    globalQpsStrategy = chooseStrategy(globalLimitKey, globalLimitProperty.getLong((long) Integer.MAX_VALUE), globalBucketProperty.getLong(), globalStrategyProperty.getString());
    globalStrategyProperty.addCallback(() -> {
        globalQpsStrategy = chooseStrategy(globalLimitKey, globalLimitProperty.getLong((long) Integer.MAX_VALUE), globalBucketProperty.getLong(), globalStrategyProperty.getString());
        LOGGER.info("Global flow control strategy update, value = [{}]", globalStrategyProperty.getString());
    });
    globalLimitProperty.addCallback(() -> {
        globalQpsStrategy.setQpsLimit(globalLimitProperty.getLong((long) Integer.MAX_VALUE));
        LOGGER.info("Global qps limit update, value = [{}]", globalLimitProperty.getLong());
    });
    globalBucketProperty.addCallback(() -> {
        globalQpsStrategy.setBucketLimit(globalBucketProperty.getLong());
        LOGGER.info("Global bucket limit update, value = [{}]", globalBucketProperty.getLong());
    });
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty)

Example 7 with DynamicProperty

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

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 8 with DynamicProperty

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

the class TestPriorityPropertyManager method testConfigurationsAreGCCollected.

@Test
public void testConfigurationsAreGCCollected() {
    long timeBegin = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            TestConfigObjectFactory.ConfigWithAnnotation configConfigObject = priorityPropertyManager.createConfigObject(TestConfigObjectFactory.ConfigWithAnnotation.class);
            Assert.assertEquals("abc", configConfigObject.strDef);
            PriorityProperty<Long> configPriorityProperty = propertyFactory.getOrCreate(Long.class, -1L, -2L, keys);
            Assert.assertEquals(-2L, (long) configPriorityProperty.getValue());
        }
    }
    waitKeyForGC(priorityPropertyManager);
    Assert.assertTrue(priorityPropertyManager.getConfigObjectMap().isEmpty());
    for (DynamicProperty property : ConfigUtil.getAllDynamicProperties().values()) {
        Assert.assertTrue(ConfigUtil.getCallbacks(property).isEmpty());
    }
    System.out.println("Token : " + (System.currentTimeMillis() - timeBegin));
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty) TestConfigObjectFactory(org.apache.servicecomb.config.inject.TestConfigObjectFactory) Test(org.junit.jupiter.api.Test)

Example 9 with DynamicProperty

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

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)

Example 10 with DynamicProperty

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

the class ConsumerQpsControllerManager method initConfig.

private void initConfig(OperationMeta operationMeta, String key) {
    if (watchedKeySet.contains(key)) {
        return;
    }
    watchedKeySet.add(key);
    String configKey = Config.CONSUMER_LIMIT_KEY_PREFIX + key;
    DynamicProperty property = DynamicProperty.getInstance(configKey);
    initQpsLimit(key, getIntegerLimitProperty(property));
    property.addCallback(() -> {
        updateQpsLimit(key, getIntegerLimitProperty(property));
        QpsController qpsController = findReference(operationMeta);
        objMap.put(operationMeta.getMicroserviceQualifiedName(), qpsController);
    });
    initQpsLimit(key, property.getInteger());
}
Also used : DynamicProperty(com.netflix.config.DynamicProperty)

Aggregations

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