Skip to content

Commit

Permalink
Fix defaults for archaius2 environment seeding so EC2 properties are …
Browse files Browse the repository at this point in the history
…always loaded first and can be overridden by profile/env properties

Move api classes to karyon3-api
  • Loading branch information
elandau committed Nov 24, 2015
1 parent 8dc570b commit 2cae60b
Show file tree
Hide file tree
Showing 35 changed files with 110 additions and 762 deletions.
28 changes: 28 additions & 0 deletions karyon3-api/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2015 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.
*/

apply plugin: 'java'

dependencies {
compile 'javax.inject:javax.inject:1'
}

eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
import com.netflix.archaius.interpolate.ConfigStrLookup;
import com.netflix.archaius.readers.PropertiesConfigReader;
import com.netflix.karyon.AbstractPropertySource;
import com.netflix.karyon.KaryonBinder;
import com.netflix.karyon.KaryonModule;
import com.netflix.karyon.PropertySource;
import com.netflix.karyon.TypeLiteralMatchers;
import com.netflix.karyon.annotations.Profiles;
import com.netflix.karyon.archaius.admin.ArchaiusAdminModule;
import com.netflix.karyon.spi.KaryonBinder;
import com.netflix.karyon.spi.KaryonModule;
import com.netflix.karyon.spi.PropertySource;

/**
* Module to set up archaius in a Karyon3 application.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.google.inject.Binder;
import com.google.inject.Key;
import com.netflix.archaius.ConfigProxyFactory;
import com.netflix.karyon.AutoBinder;
import com.netflix.karyon.spi.AutoBinder;

/**
* Autobinder to create proxies for any interface containing the archaius
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Default values for internal karyon environment properties

karyon.domain=
karyon.hostname=localhost
karyon.publicHostname=localhost
Expand All @@ -14,6 +16,7 @@ karyon.asg=asg-dev
karyon.cluster=cluster-dev
karyon.stack=

# Backwards compatible mappings for the legacy @ prefixed properties
@domain=${karyon.domain}
@hostname=${karyon.hostname}
@publicHostname=${karyon.publicHostname}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# This final contains the default mapping of Netflix EC2 environment settings
# to Karyon's environment agnostic naming.

karyon.domain=${EC2_DOMAIN}
karyon.hostname=${EC2_HOSTNAME}
karyon.publicHostname=${EC2_PUBLIC_HOSTNAME}
karyon.publicIpv4=${EC2_PUBLIC_IPV4}
karyon.localHostname=${EC2_LOCAL_HOSTNAME}
karyon.localIpv4=${EC2_LOCAL_IPV4}
karyon.datacenter=cloud
karyon.zoneId=${EC2_AVAILABILITY_ZONE}
karyon.serverId=${EC2_INSTANCE_ID}
karyon.ami=${EC2_AMI_ID}
karyon.region=${EC2_REGION}

# Backwards compatible mappings for the legacy @ prefixed properties
@domain=${karyon.domain}
@hostname=${karyon.hostname}
@publicHostname=${karyon.publicHostname}
Expand All @@ -16,14 +32,3 @@
@appId=${karyon.appId}
@countries=${karyon.countries}

karyon.domain=${EC2_DOMAIN}
karyon.hostname=${EC2_HOSTNAME}
karyon.publicHostname=${EC2_PUBLIC_HOSTNAME}
karyon.publicIpv4=${EC2_PUBLIC_IPV4}
karyon.localHostname=${EC2_LOCAL_HOSTNAME}
karyon.localIpv4=${EC2_LOCAL_IPV4}
karyon.datacenter=cloud
karyon.zoneId=${EC2_AVAILABILITY_ZONE}
karyon.serverId=${EC2_INSTANCE_ID}
karyon.ami=${EC2_AMI_ID}
karyon.region=${EC2_REGION}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.netflix.archaius.config.SettableConfig;
import com.netflix.archaius.exceptions.ConfigException;
import com.netflix.archaius.inject.RemoteLayer;
import com.netflix.archaius.visitor.PrintStreamVisitor;
import com.netflix.karyon.Karyon;

public class ArchaiusKaryonModuleTest {
Expand Down Expand Up @@ -88,14 +87,14 @@ public void testLibrariesOverrideConfig() throws ConfigException {
Foo foo = injector.getInstance(Foo.class);
Config config = injector.getInstance(Config.class);

config.accept(new PrintStreamVisitor());
System.out.println("Value: " + config.getString("foo_override"));
assertThat(config.getString("foo_override"), equalTo("code"));
}

@Test
public void testLibrariesOverrideProperties() throws ConfigException {
Injector injector = Karyon.newBuilder()
.addProfile("local")
.addModules(new ArchaiusKaryonModule()
.withLibraryOverrides("foo", singletonProperties("foo_override", "code"))
)
Expand Down
1 change: 1 addition & 0 deletions karyon3-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
apply plugin: 'java'

dependencies {
compile project(":karyon3-api")
compile project(":karyon3-admin")
compile "com.netflix.governator:governator-core:${governator_version}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.lang.reflect.Method;

import com.netflix.karyon.spi.PropertySource;

public abstract class AbstractPropertySource implements PropertySource {
@Override
public <T> T get(String key, Class<T> type) {
Expand Down
4 changes: 4 additions & 0 deletions karyon3-core/src/main/java/com/netflix/karyon/Karyon.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
import com.netflix.karyon.annotations.Arguments;
import com.netflix.karyon.annotations.Profiles;
import com.netflix.karyon.conditional.ConditionalSupportModule;
import com.netflix.karyon.spi.AutoBinder;
import com.netflix.karyon.spi.KaryonBinder;
import com.netflix.karyon.spi.KaryonModule;
import com.netflix.karyon.spi.ModuleListTransformer;
import com.netflix.karyon.spi.PropertySource;

/**
* Main entry point for creating a LifecycleInjector with guice extensions such as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.netflix.governator.guice.lazy.FineGrainedLazySingletonScope;
import com.netflix.governator.guice.lazy.LazySingleton;
import com.netflix.governator.guice.lazy.LazySingletonScope;
import com.netflix.karyon.spi.PropertySource;

/**
* Adds support for standard lifecycle annotations @PostConstruct and @PreDestroy to Guice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.matcher.Matcher;
import com.netflix.karyon.spi.AutoBinder;

class MatchingAutoBinder<T extends TypeLiteral<?>> implements AutoBinder {
final Matcher<T> matcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.netflix.karyon.spi.PropertySource;

public class PropertiesPropertySource extends AbstractPropertySource {
private Properties props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.inject.Binder;
import com.google.inject.Key;
import com.netflix.karyon.spi.AutoBinder;
import com.netflix.karyon.spi.PropertySource;

public class PropertySourceAutoBinder implements AutoBinder {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import javax.inject.Inject;
import javax.inject.Singleton;

import com.netflix.karyon.PropertySource;
import com.netflix.karyon.conditional.annotations.ConditionalOnProperty;
import com.netflix.karyon.spi.PropertySource;

@Singleton
public class ConditionalOnPropertyMatcher implements ConditionalMatcher<ConditionalOnProperty>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@
@Documented
public @interface ProvidesConditionally {
/**
* If set to true this bindings will be used if not other condition is met (even if this bindings
* @return If set to true this bindings will be used if not other condition is met (even if this bindings
* condition is not met). Only one ProvidesConditionally for a type may hav isDefault set to true
* @return
*/
boolean isDefault() default false;
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 2cae60b

Please sign in to comment.