Search in sources :

Example 1 with Config

use of com.netflix.archaius.api.Config in project titus-control-plane by Netflix.

the class Archaius2Ext method newConfiguration.

/**
 * Create Archaius based configuration object initialized with default values. Defaults can be overridden
 * by providing key/value pairs as parameters.
 */
public static <C> C newConfiguration(Class<C> configType, String... keyValuePairs) {
    if (keyValuePairs.length == 0) {
        return DEFAULT_CONFIG_PROXY_FACTORY.newProxy(configType);
    }
    Preconditions.checkArgument(keyValuePairs.length % 2 == 0, "Expected even number of arguments");
    Map<String, String> props = new HashMap<>();
    int len = keyValuePairs.length / 2;
    for (int i = 0; i < len; i++) {
        props.put(keyValuePairs[i * 2], keyValuePairs[i * 2 + 1]);
    }
    Config config = new MapConfig(props);
    return newConfiguration(configType, config);
}
Also used : HashMap(java.util.HashMap) MapConfig(com.netflix.archaius.config.MapConfig) Config(com.netflix.archaius.api.Config) MapConfig(com.netflix.archaius.config.MapConfig)

Example 2 with Config

use of com.netflix.archaius.api.Config in project spectator by Netflix.

the class NetflixConfigTest method defaultOverrides.

@Test
public void defaultOverrides() {
    Config overrides = MapConfig.builder().put("NETFLIX_ENVIRONMENT", "prod").put("substitutions", "${NETFLIX_ENVIRONMENT}-${EC2_OWNER_ID}").build();
    Config config = NetflixConfig.createConfig(overrides);
    Assertions.assertEquals("prod", config.getString("NETFLIX_ENVIRONMENT"));
    Assertions.assertEquals("unknown", config.getString("EC2_OWNER_ID"));
    Assertions.assertEquals("us-east-1", config.getString("EC2_REGION"));
    Assertions.assertEquals("prod-unknown", config.getString("substitutions"));
}
Also used : MapConfig(com.netflix.archaius.config.MapConfig) Config(com.netflix.archaius.api.Config) Test(org.junit.jupiter.api.Test)

Example 3 with Config

use of com.netflix.archaius.api.Config in project spectator by Netflix.

the class NetflixConfigTest method defaultEnvVarsAreSet.

@Test
public void defaultEnvVarsAreSet() {
    Config config = NetflixConfig.loadPropFiles();
    Assertions.assertEquals("test", config.getString("NETFLIX_ENVIRONMENT"));
    Assertions.assertEquals("unknown", config.getString("EC2_OWNER_ID"));
    Assertions.assertEquals("us-east-1", config.getString("EC2_REGION"));
}
Also used : MapConfig(com.netflix.archaius.config.MapConfig) Config(com.netflix.archaius.api.Config) Test(org.junit.jupiter.api.Test)

Example 4 with Config

use of com.netflix.archaius.api.Config in project iep by Netflix.

the class PlatformServiceModuleTest method getValues.

@Test
public void getValues() {
    Config cfg = Guice.createInjector(testModule).getInstance(Config.class);
    Assert.assertEquals("b", cfg.getString("a"));
    Assert.assertEquals("dynamic", cfg.getString("c"));
}
Also used : Config(com.netflix.archaius.api.Config) DefaultSettableConfig(com.netflix.archaius.config.DefaultSettableConfig) SettableConfig(com.netflix.archaius.api.config.SettableConfig) Test(org.junit.Test)

Example 5 with Config

use of com.netflix.archaius.api.Config in project iep by Netflix.

the class PlatformServiceModuleTest method getValueRuntime.

@Test
public void getValueRuntime() {
    Key<SettableConfig> key = Key.get(SettableConfig.class, RuntimeLayer.class);
    Injector injector = Guice.createInjector(testModule);
    SettableConfig runtime = injector.getInstance(key);
    Config root = injector.getInstance(Config.class);
    Assert.assertEquals("b", root.getString("a"));
    Assert.assertEquals("dynamic", root.getString("c"));
    runtime.setProperty("a", "runtime");
    runtime.setProperty("c", "runtime");
    Assert.assertEquals("runtime", root.getString("a"));
    Assert.assertEquals("runtime", root.getString("c"));
    runtime.clearProperty("a");
    Assert.assertEquals("b", root.getString("a"));
    Assert.assertEquals("runtime", root.getString("c"));
}
Also used : DefaultSettableConfig(com.netflix.archaius.config.DefaultSettableConfig) SettableConfig(com.netflix.archaius.api.config.SettableConfig) Injector(com.google.inject.Injector) Config(com.netflix.archaius.api.Config) DefaultSettableConfig(com.netflix.archaius.config.DefaultSettableConfig) SettableConfig(com.netflix.archaius.api.config.SettableConfig) Test(org.junit.Test)

Aggregations

Config (com.netflix.archaius.api.Config)8 MapConfig (com.netflix.archaius.config.MapConfig)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 SettableConfig (com.netflix.archaius.api.config.SettableConfig)2 DefaultSettableConfig (com.netflix.archaius.config.DefaultSettableConfig)2 Test (org.junit.jupiter.api.Test)2 Iterators (com.google.common.collect.Iterators)1 Injector (com.google.inject.Injector)1 DefaultPropertyFactory (com.netflix.archaius.DefaultPropertyFactory)1 ConfigListener (com.netflix.archaius.api.ConfigListener)1 PropertyFactory (com.netflix.archaius.api.PropertyFactory)1 JobAttributes (com.netflix.titus.api.jobmanager.JobAttributes)1 JOB_ATTRIBUTES_RUNTIME_PREDICTION_SELECTOR_INFO (com.netflix.titus.api.jobmanager.JobAttributes.JOB_ATTRIBUTES_RUNTIME_PREDICTION_SELECTOR_INFO)1 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)1 DateTimeExt (com.netflix.titus.common.util.DateTimeExt)1 PropertiesExt (com.netflix.titus.common.util.PropertiesExt)1 Archaius2Ext (com.netflix.titus.common.util.archaius2.Archaius2Ext)1 CloseableReference (com.netflix.titus.common.util.closeable.CloseableReference)1 JobRuntimePrediction (com.netflix.titus.runtime.connector.prediction.JobRuntimePrediction)1