Skip to content

Commit

Permalink
Merge pull request #242 from brharrington/archaius2
Browse files Browse the repository at this point in the history
update to archaius 2.0.5
  • Loading branch information
brharrington committed Apr 21, 2016
2 parents 4e2edd3 + 35a20d9 commit f8a7150
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 96 deletions.
91 changes: 38 additions & 53 deletions iep-config/src/main/java/com/netflix/iep/config/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
*/
package com.netflix.iep.config;

import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.util.Modules;
import com.netflix.archaius.config.CompositeConfig;
import com.netflix.archaius.api.config.CompositeConfig;
import com.netflix.archaius.api.inject.RemoteLayer;
import com.netflix.archaius.config.DefaultCompositeConfig;
import com.netflix.archaius.config.MapConfig;
import com.netflix.archaius.guice.ArchaiusModule;
import com.netflix.archaius.inject.ApplicationLayer;
import com.netflix.archaius.inject.RemoteLayer;
import com.netflix.archaius.typesafe.TypesafeConfig;
import com.netflix.iep.admin.AdminModule;
import com.netflix.iep.platformservice.ApplicationLayer;
import com.netflix.iep.platformservice.PlatformServiceModule;
import com.netflix.iep.platformservice.PropsEndpoint;
import com.netflix.spectator.api.Spectator;
Expand All @@ -35,7 +34,7 @@
import javax.inject.Singleton;
import java.util.Properties;

public class ConfigModule extends AbstractModule {
public class ConfigModule extends ArchaiusModule {

private final String[] propFiles;

Expand All @@ -47,11 +46,12 @@ public ConfigModule(String[] propFiles) {
this.propFiles = propFiles;
}

@Override protected void configure() {
Module m = Modules
.override(new ArchaiusModule())
.with(new OverrideModule(propFiles));
install(m);
@Override protected void configureArchaius() {
install(new AdminModule());
AdminModule.endpointsBinder(binder()).addBinding("/props").to(PropsEndpoint.class);
bindApplicationConfigurationOverride()
.to(Key.get(com.netflix.archaius.api.Config.class, ApplicationLayer.class));
bind(DynamicPropertiesConfiguration.class).asEagerSingleton();
}

@Override public boolean equals(Object obj) {
Expand All @@ -62,48 +62,33 @@ public ConfigModule(String[] propFiles) {
return getClass().hashCode();
}

private static class OverrideModule extends AbstractModule {

private final String[] propFiles;

OverrideModule(String[] propFiles) {
this.propFiles = propFiles;
}

@Override protected void configure() {
install(new AdminModule());
AdminModule.endpointsBinder(binder()).addBinding("/props").to(PropsEndpoint.class);
bind(DynamicPropertiesConfiguration.class).asEagerSingleton();
}

@Provides
@Singleton
Config providesTypesafeConfig() {
final String prop = "netflix.iep.env.account-type";
final Config baseConfig = ConfigFactory.load();
final String envConfigName = "iep-" + baseConfig.getString(prop) + ".conf";
final Config envConfig = ConfigFactory.parseResources(envConfigName);
return envConfig.withFallback(baseConfig).resolve();
}
@Provides
@Singleton
Config providesTypesafeConfig() {
final String prop = "netflix.iep.env.account-type";
final Config baseConfig = ConfigFactory.load();
final String envConfigName = "iep-" + baseConfig.getString(prop) + ".conf";
final Config envConfig = ConfigFactory.parseResources(envConfigName);
return envConfig.withFallback(baseConfig).resolve();
}

@Provides
@Singleton
@RemoteLayer
private com.netflix.archaius.Config providesOverrideConfig(Config cfg) throws Exception {
return PlatformServiceModule.getDynamicConfig(Spectator.globalRegistry(), cfg);
}
@Provides
@Singleton
@RemoteLayer
private com.netflix.archaius.api.Config providesOverrideConfig(Config cfg) throws Exception {
return PlatformServiceModule.getDynamicConfig(Spectator.globalRegistry(), cfg);
}

@Provides
@Singleton
@ApplicationLayer
private CompositeConfig providesAppConfig(Config cfg) throws Exception {
final Properties props = (propFiles == null)
? ScopedPropertiesLoader.load()
: ScopedPropertiesLoader.load(propFiles);
final CompositeConfig app = new CompositeConfig();
app.addConfig("scoped", new MapConfig(props));
app.addConfig("typesafe", new TypesafeConfig(cfg));
return app;
}
@Provides
@Singleton
@ApplicationLayer
private CompositeConfig providesAppConfig(Config cfg) throws Exception {
final Properties props = (propFiles == null)
? ScopedPropertiesLoader.load()
: ScopedPropertiesLoader.load(propFiles);
final CompositeConfig app = new DefaultCompositeConfig();
app.addConfig("scoped", new MapConfig(props));
app.addConfig("typesafe", new TypesafeConfig(cfg));
return app;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.util.Modules;
import com.netflix.archaius.api.inject.RemoteLayer;
import com.netflix.archaius.config.PollingDynamicConfig;
import com.netflix.archaius.config.polling.FixedPollingStrategy;
import com.netflix.archaius.config.polling.PollingResponse;
import com.netflix.archaius.config.CompositeConfig;
import com.netflix.archaius.config.MapConfig;
import com.netflix.archaius.guice.ArchaiusModule;
import com.netflix.archaius.inject.ApplicationLayer;
import com.netflix.archaius.inject.RemoteLayer;
import com.netflix.archaius.typesafe.TypesafeConfig;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
Expand Down Expand Up @@ -86,15 +85,15 @@ Config providesTypesafeConfig() {
@Provides
@Singleton
@RemoteLayer
private com.netflix.archaius.Config providesOverrideConfig(Config cfg) throws Exception {
private com.netflix.archaius.api.Config providesOverrideConfig(Config cfg) throws Exception {
return new PollingDynamicConfig(
PollingResponse::noop,
new FixedPollingStrategy(60000, TimeUnit.MILLISECONDS));
}

@Provides
@Singleton
@ApplicationLayer
// TODO @ApplicationLayer
private CompositeConfig providesAppConfig(Config cfg) throws Exception {
final Properties props = (propFiles == null)
? ScopedPropertiesLoader.load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/
package com.netflix.iep.config;

import com.netflix.archaius.api.Property;
import com.netflix.archaius.api.PropertyFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.inject.Singleton;

import com.netflix.archaius.Property;
import com.netflix.archaius.PropertyFactory;

@Singleton
public class DynamicPropertiesConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.google.common.io.Resources;
import com.google.common.base.Charsets;

import com.netflix.archaius.api.Config;
import com.netflix.config.ConfigurationManager;
import com.netflix.archaius.Config;
import com.netflix.archaius.config.MapConfig;

public class TestResourceConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static org.junit.Assert.*;

import com.netflix.archaius.DefaultPropertyFactory;
import com.netflix.archaius.PropertyFactory;
import com.netflix.archaius.api.PropertyFactory;
import com.netflix.archaius.config.MapConfig;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import static org.junit.Assert.*;

import com.netflix.archaius.Config;
import com.netflix.archaius.DefaultPropertyFactory;
import com.netflix.archaius.PropertyFactory;
import com.netflix.archaius.api.Config;
import com.netflix.archaius.api.PropertyFactory;
import org.junit.BeforeClass;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.util.Modules;
import com.netflix.archaius.Config;
import com.netflix.archaius.api.Config;
import com.netflix.archaius.bridge.StaticArchaiusBridgeModule;
import com.netflix.config.ConfigurationManager;
import com.netflix.config.DeploymentContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
import com.google.inject.Module;
import com.google.inject.name.Names;
import com.google.inject.util.Modules;
import com.netflix.archaius.Config;
import com.netflix.archaius.api.Config;
import com.netflix.archaius.api.config.SettableConfig;
import com.netflix.archaius.api.inject.RemoteLayer;
import com.netflix.archaius.api.inject.RuntimeLayer;
import com.netflix.archaius.bridge.StaticAbstractConfiguration;
import com.netflix.archaius.bridge.StaticDeploymentContext;
import com.netflix.archaius.config.CompositeConfig;
import com.netflix.archaius.config.DefaultSettableConfig;
import com.netflix.archaius.config.MapConfig;
import com.netflix.archaius.config.SettableConfig;
import com.netflix.archaius.guice.ArchaiusModule;
import com.netflix.archaius.inject.ApplicationLayer;
import com.netflix.archaius.inject.RemoteLayer;
import com.netflix.archaius.inject.RuntimeLayer;
import org.apache.commons.configuration.Configuration;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -47,8 +46,8 @@ public class ArchaiusModuleTest {

private static final Key<Configuration> IEP_CONFIG = Key.get(Configuration.class, Names.named("IEP"));

private Module overrideModule = new AbstractModule() {
@Override protected void configure() {
private Module overrideModule = new ArchaiusModule() {
@Override protected void configureArchaius() {
try {
MapConfig cfg = MapConfig.builder()
.put("netflix.iep.archaius.scope.environment", "test")
Expand All @@ -63,9 +62,7 @@ public class ArchaiusModuleTest {
.put("a", "b")
.put("c", "d")
.build();
CompositeConfig app = new CompositeConfig();
app.addConfig("MAP", cfg);
bind(CompositeConfig.class).annotatedWith(ApplicationLayer.class).toInstance(app);
bindApplicationConfigurationOverride().toInstance(cfg);

DefaultSettableConfig dynamic = new DefaultSettableConfig();
dynamic.setProperty("c", "dynamic");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2014-2016 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.iep.platformservice;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

@Qualifier
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ApplicationLayer {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.netflix.archaius.config.PollingStrategy;
import com.netflix.archaius.api.config.PollingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/
package com.netflix.iep.platformservice;

import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.netflix.archaius.config.CompositeConfig;
import com.netflix.archaius.api.config.PollingStrategy;
import com.netflix.archaius.api.inject.RemoteLayer;
import com.netflix.archaius.config.EmptyConfig;
import com.netflix.archaius.config.PollingStrategy;
import com.netflix.archaius.config.polling.PollingResponse;
import com.netflix.archaius.inject.ApplicationLayer;
import com.netflix.archaius.inject.RemoteLayer;
import com.netflix.archaius.guice.ArchaiusModule;
import com.netflix.archaius.typesafe.TypesafeConfig;
import com.netflix.iep.admin.AdminModule;
import com.netflix.spectator.api.DefaultRegistry;
Expand All @@ -40,9 +39,11 @@
/**
* Helper for configuring archaius with the Netflix dynamic property source.
*/
public final class PlatformServiceModule extends AbstractModule {
public final class PlatformServiceModule extends ArchaiusModule {

@Override protected void configure() {
@Override protected void configureArchaius() {
bindApplicationConfigurationOverride()
.to(Key.get(com.netflix.archaius.api.Config.class, ApplicationLayer.class));
AdminModule.endpointsBinder(binder()).addBinding("/props").to(PropsEndpoint.class);
}

Expand All @@ -59,18 +60,16 @@ Config providesTypesafeConfig() {
@Provides
@Singleton
@RemoteLayer
private com.netflix.archaius.Config providesOverrideConfig(OptionalInjections opts, Config cfg)
private com.netflix.archaius.api.Config providesOverrideConfig(OptionalInjections opts, Config cfg)
throws Exception {
return getDynamicConfig(opts.getRegistry(), cfg);
}

@Provides
@Singleton
@ApplicationLayer
private CompositeConfig providesAppConfig(final Config application) throws Exception {
CompositeConfig app = new CompositeConfig();
app.addConfig("TYPESAFE", new TypesafeConfig(application));
return app;
private com.netflix.archaius.api.Config providesAppConfig(final Config application) throws Exception {
return new TypesafeConfig(application);
}

@Override public boolean equals(Object obj) {
Expand All @@ -95,7 +94,7 @@ private static PollingStrategy getPollingStrategy(Config cfg) {
return new FixedPollingStrategy(interval, TimeUnit.MILLISECONDS, cfg.getBoolean(propSyncInit));
}

public static com.netflix.archaius.Config getDynamicConfig(Registry registry, Config cfg)
public static com.netflix.archaius.api.Config getDynamicConfig(Registry registry, Config cfg)
throws Exception {
final String propUseDynamic = "netflix.iep.archaius.use-dynamic";
return (cfg.getBoolean(propUseDynamic))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

import com.netflix.archaius.api.config.PollingStrategy;
import com.netflix.archaius.config.AbstractConfig;
import com.netflix.archaius.config.PollingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.netflix.iep.platformservice;

import com.netflix.archaius.Config;
import com.netflix.archaius.api.Config;
import com.netflix.iep.admin.HttpEndpoint;

import javax.inject.Inject;
Expand Down
Loading

0 comments on commit f8a7150

Please sign in to comment.