com.netflix.archaius.config.MapConfig Java Examples
The following examples show how to use
com.netflix.archaius.config.MapConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Archaius2Ext.java From titus-control-plane with Apache License 2.0 | 6 votes |
/** * 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); }
Example #2
Source File: TitusMaster.java From titus-control-plane with Apache License 2.0 | 5 votes |
private static MapConfig loadPropertiesFile(String propertiesFile) { if (propertiesFile == null) { return MapConfig.from(Collections.emptyMap()); } Properties properties = new Properties(); try (FileReader fr = new FileReader(propertiesFile)) { properties.load(fr); } catch (IOException e) { throw new IllegalArgumentException("Cannot load file: " + propertiesFile, e); } return MapConfig.from(properties); }
Example #3
Source File: JobRuntimePredictionSelectorsTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void testAboveThresholdFromConfig() { ImmutableMap<String, String> config = ImmutableMap.<String, String>builder() .put("runtimeThresholdInSeconds", "60") .put("sigmaThreshold", "10") .build(); JobRuntimePredictionSelector selector = aboveThreshold(new MapConfig(config), METADATA); checkSelection(selector.apply(JOB_DESCRIPTOR, JOB_PREDICTIONS)); }
Example #4
Source File: JobRuntimePredictionSelectorsTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void testAboveThresholds() { ImmutableMap<String, String> config = ImmutableMap.<String, String>builder() .put("root.cellA.runtimeThresholdInSeconds", "60") .put("root.cellA.sigmaThreshold", "10") .put("root.cellB.runtimeThresholdInSeconds", "6") .put("root.cellB.sigmaThreshold", "1") .build(); Map<String, JobRuntimePredictionSelector> selectors = aboveThresholds(new MapConfig(config).getPrefixedView("root"), METADATA); checkSelection(selectors.get("cellA").apply(JOB_DESCRIPTOR, JOB_PREDICTIONS)); assertThat(selectors.get("cellB").apply(JOB_DESCRIPTOR, JOB_PREDICTIONS)).isEmpty(); }
Example #5
Source File: TitusGateway.java From titus-control-plane with Apache License 2.0 | 5 votes |
private static MapConfig loadPropertiesFile(String propertiesFile) { if (propertiesFile == null) { return MapConfig.from(Collections.emptyMap()); } Properties properties = new Properties(); try (FileReader fr = new FileReader(propertiesFile)) { properties.load(fr); } catch (IOException e) { throw new IllegalArgumentException("Cannot load file: " + propertiesFile, e); } return MapConfig.from(properties); }
Example #6
Source File: ArchaiusTokenBucketAdmissionConfigurationParserTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void testValidConfiguration() { MapConfig config = new MapConfig(CollectionsExt.merge( TokenBucketTestConfigurations.NOT_SHARED_PROPERTIES, SHARED_ANY_PROPERTIES )); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); List<TokenBucketConfiguration> configuration = parser.get(); assertThat(configuration).hasSize(2); assertThat(configuration.get(0)).isEqualTo(TokenBucketTestConfigurations.NOT_SHARED_CONFIGURATION); assertThat(configuration.get(1)).isEqualTo(TokenBucketTestConfigurations.SHARED_ANY_CONFIGURATION); }
Example #7
Source File: ArchaiusTokenBucketAdmissionConfigurationParserTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void testPartiallyInvalid() { MapConfig config = new MapConfig(CollectionsExt.merge( TokenBucketTestConfigurations.NOT_SHARED_BAD_PROPERTIES, SHARED_ANY_PROPERTIES )); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); List<TokenBucketConfiguration> configuration = parser.get(); assertThat(configuration).hasSize(1); assertThat(configuration.get(0).getName()).isEqualTo(SHARED_ANY_CONFIGURATION.getName()); }
Example #8
Source File: ArchaiusTokenBucketAdmissionConfigurationParserTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Test public void testAllInvalid() { MapConfig config = new MapConfig(CollectionsExt.merge( TokenBucketTestConfigurations.NOT_SHARED_BAD_PROPERTIES, TokenBucketTestConfigurations.SHARED_ANY_BAD_PROPERTIES )); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); assertThat(parser.get()).isEmpty(); }
Example #9
Source File: NetflixConfig.java From spectator with Apache License 2.0 | 5 votes |
static Config loadPropFiles() { final Properties props = new Properties(); Env.addDefaults(props); final String env = Env.environment(); final String acctId = Env.accountId(); tryLoadingConfig(props, "atlas_plugin"); tryLoadingConfig(props, "atlas_plugin-" + env); tryLoadingConfig(props, "atlas_plugin-acct-" + acctId); return MapConfig.from(props); }
Example #10
Source File: NetflixConfigTest.java From spectator with Apache License 2.0 | 5 votes |
@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")); }
Example #11
Source File: DIBase.java From EVCache with Apache License 2.0 | 5 votes |
@BeforeSuite public void setupEnv() { Properties props = getProps(); try { LifecycleInjectorBuilder builder = LifecycleInjector.builder(); builder.withModules( new EurekaClientModule(), new EVCacheModule(), new DIConnectionModule(), new SpectatorModule(), new ArchaiusModule() { protected void configureArchaius() { bindApplicationConfigurationOverride().toInstance(MapConfig.from(props)); }; } ); injector = builder.build().createInjector(); lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); injector.getInstance(ApplicationInfoManager.class); final EVCacheModule lib = injector.getInstance(EVCacheModule.class); manager = injector.getInstance(EVCacheClientPoolManager.class); } catch (Throwable e) { e.printStackTrace(); log.error(e.getMessage(), e); } }
Example #12
Source File: Archaius2ExtTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Test public void testConfigurationWithNoPrefix() { MapConfig config = new MapConfig(Collections.singletonMap("string", "HELLO")); assertThat(Archaius2Ext.newConfiguration(MyConfig.class, config).getString()).isEqualTo("HELLO"); }
Example #13
Source File: Archaius2ExtTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Test public void testConfigurationWithPrefix() { MapConfig config = new MapConfig(Collections.singletonMap("root.string", "HELLO")); assertThat(Archaius2Ext.newConfiguration(MyConfig.class, "root", config).getString()).isEqualTo("HELLO"); }
Example #14
Source File: ArchaiusTokenBucketAdmissionConfigurationParserTest.java From titus-control-plane with Apache License 2.0 | 4 votes |
@Test public void testNoConfiguration() { MapConfig config = new MapConfig(new HashMap<>()); ArchaiusTokenBucketAdmissionConfigurationParser parser = new ArchaiusTokenBucketAdmissionConfigurationParser(config); assertThat(parser.get()).isEmpty(); }
Example #15
Source File: Archaius2Ext.java From titus-control-plane with Apache License 2.0 | 2 votes |
/** * Create Archaius based configuration object initialized with default values. Overrides can be provided * via the properties parameter. */ public static <C> C newConfiguration(Class<C> configType, Map<String, String> properties) { return newConfiguration(configType, new MapConfig(properties)); }