Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Configuration beyond Java EE 8

1,097 views

Published on

My talk at Javaland on Configuration beyond Java EE 8 with Apache Tamaya and some APIs as discussed on Microprofile.io.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Configuration beyond Java EE 8

  1. 1. BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH Configuration beyond Java EE Configuration with Apache Tamaya and Microprofile.io
  2. 2. Configuration beyond Java EE 828.03.2017 Anatole Tresch Principal Consultant, Trivadis AG (Switzerland) Star Spec Lead Technical Architect, Lead Engineer PPMC Member Apache Tamaya @atsticks anatole@apache.org anatole.tresch@trivadis.com 2 About Me
  3. 3. Configuration beyond Java EE 828.03.2017 Agenda 3 ● What‘s all about ? ● Framework Architecture ● Accessing Configuration ● Configuration Backends ● Configuration Runtime ● Services ● Demo / Adoption Area
  4. 4. Configuration beyond Java EE 828.03.2017 4 What‘s all about ?
  5. 5. Configuration beyond Java EE 828.03.2017 5 What is Configuration ? Simple Key/value pairs? Typed values?
  6. 6. Configuration beyond Java EE 828.03.2017 6 When is Configuration useful? Use Cases?
  7. 7. Configuration beyond Java EE 828.03.2017 7 How is it stored? Remotely or locally? Classpath, file or ...? Which format? All of the above (=multiple sources) ?
  8. 8. Configuration beyond Java EE 828.03.2017 8 When to configure? Development time ? Build/deployment time? Startup? Dynamic, anytime?
  9. 9. Configuration beyond Java EE 828.03.2017 9 Configuration Lifecycle ? Static ? Refreshing ? Changes triggered ?
  10. 10. Configuration beyond Java EE 828.03.2017 10 Do I need a runtime ? Java SE? Java EE? OSGI? Kubernetes?
  11. 11. Configuration beyond Java EE 828.03.2017 Framework Architecture
  12. 12. Configuration beyond Java EE 828.03.2017 12 What Configuration Solutions are out there? Apache Commons Config Apache Tamaya Apache Deltaspike Netflix Archaius Config Typesafe Config Microprofile.io ...
  13. 13. Configuration beyond Java EE 828.03.2017 13 Common Framework Design Accessor API Runtime Configuration Backends Extended Services API Runtime Backends Services
  14. 14. Configuration beyond Java EE 828.03.2017 Accessing Configuration
  15. 15. Configuration beyond Java EE 828.03.2017 15 Accessing configuration: Patterns Service Locator Pattern Configuration Injection Templates
  16. 16. Configuration beyond Java EE 828.03.2017 16 Configuration cfg = ConfigurationProvider.getConfiguration(); String name = cfg.get("example.name")); String nameWithDefault = cfg.getOrDefault("example.name", "N/A"); BigDecimal bd = cfg.get("example.number", BigDecimal.class); Map<String,String> properties = config.getProperties(); Accessing Config: Service Location Pattern
  17. 17. Configuration beyond Java EE 828.03.2017 17 Config config = ConfigProvider.getConfig(); Config config = ConfigProvider.getConfig( Thread.currentThread().getContextClassLoader()); String value = config.getValue("fooBar", String.class); Integer intValue = config.getValue("fooBar", Integer.class); Optional<Integer> getOptionalValue("fooBar", Integer.class);          Accessing Config: Service Location Pattern
  18. 18. Configuration beyond Java EE 828.03.2017 18 Accessing Config: Templates MyConfigClass cfg = ConfigurationInjection.getConfigurationInjector() .getCon(MyCofignfigClass.class); String name = cfg.getName(); BigDecimal bd = cfg.getNumber();
  19. 19. Configuration beyond Java EE 828.03.2017 19 Accessing Config: Injection public class NonAnnotatedConfigBean { public String simple_value = "Should be overridden!"; public String fieldKey; public String classFieldKey = "Foo"; public String fullKey; public String test2 = "This is not set."; } public class AnnotatedBean{ @Config(value = {"foo.bar.myprop", "mp"}, defaultValue = "ET") private String simpleValue; @Config String anotherValue; }
  20. 20. Configuration beyond Java EE 828.03.2017 20 Accessing Config: CDI public class AnnotatedBean{ @Inject @Config(value = {"foo.bar.myprop", "mp"}, defaultValue = "ET") private String simpleValue; @Inject @Config String anotherValue; }
  21. 21. Configuration beyond Java EE 828.03.2017 21 Accessing Config: CDI public class AnnotatedBean{ @Inject @ConfigProperty(name = "foo.bar.myprop", defaultValue = "ET") private String simpleValue; @Inject @ConfigProperty(name = "foo.bar.myprop") String anotherValue; }
  22. 22. Configuration beyond Java EE 828.03.2017 Configuration Backends
  23. 23. Configuration beyond Java EE 828.03.2017 23 ● System-, Environment Properties, CLI Args ● Files, Classpath Resources ● Git, Subversion ● Databases ● Remote Services (etcd, consul) ● Distributed Caches/Grids (Redis, Hazelcast, Infinispan etc) ● ... Configuration Backends
  24. 24. Configuration beyond Java EE 828.03.2017 Backend Model: ConfigSource 24 ● Add dependency org.apache.tamaya:core: 0.2-incubating ● Add Config to META-INF/javaconfiguration.properties ● GO! public interface ConfigSource {     String getValue(String propertyName);         Map<String, String> getProperties();     default int getOrdinal() { return 100; }     String getName(); }
  25. 25. Configuration beyond Java EE 828.03.2017 Backend Model: PropertySource 25 ● Add dependency org.apache.tamaya:core: 0.2-incubating ● Add Config to META-INF/javaconfiguration.properties ● GO! public interface PropertySource {     PropertyValue get(String key);         Map<String, PropertyValue> getProperties();          int getOrdinal();     String getName();     boolean isScannable(); }
  26. 26. Configuration beyond Java EE 828.03.2017 Backend Model: PropertyValue 26 ● Add dependency org.apache.tamaya:core: 0.2-incubating ● Add Config to META-INF/javaconfiguration.properties ● GO! public final class PropertyValue{ public String getKey(); public String getValue(); public String get(String key); public Map<String,String> getMetaEntries(); ... }
  27. 27. Configuration beyond Java EE 828.03.2017 27 Programmatic Configuration Creation
  28. 28. Configuration beyond Java EE 828.03.2017 ConfigurationContextBuilder 28 ● Add dependencyConfigurationContext context =                     ConfigurationProvider.getConfigurationContextBuilder()                 .addPropertySources(testPropertySource, testPS2)                 .loadDefaultPropertyFilters()                 .addPropertyFilter(myFilter)                 .build(); Configuration config = builder.createConfig(context); // Optionally ConfigurationProvider.setConfiguration(config);
  29. 29. Configuration beyond Java EE 828.03.2017 ConfigurationBuilder 29 ● Add dependencyConfigBuilder builder; Configuration config =                     builder                 .withSources(testPropertySource, testPS2)                 .build();
  30. 30. Configuration beyond Java EE 828.03.2017 Configuration Runtime: Apache Tamaya
  31. 31. Configuration beyond Java EE 828.03.2017 31 ● Just Java 7 or higher ! What I need to run Tamaya ? Configuration Cluster Java EE Tamaya Java SE Tamaya Tamaya Vertx.io Tamaya TomEE Tamaya Spring Tamaya OSGI
  32. 32. Configuration beyond Java EE 828.03.2017 32 And how does it work ?
  33. 33. Configuration beyond Java EE 828.03.2017 Apache Tamaya in 120 seconds... 33 1.Configuration = ordered list of PropertySources 2.Properties found are combined using a CombinationPolicy 3.Raw properties are filtered by PropertyFilter 4.For typed access PropertyConverters  have to do work 5.Extensions add more features (discussed later) 6.Component Lifecycle is controlled by the ServiceContextManager ConfigurationContext PropertyFilters PropertySource PropertySource PropertySource PropertySource Configuration CombinationPolicy PropertyProviders <provides> PropertyConverter
  34. 34. Configuration beyond Java EE 828.03.2017 Configuration Services
  35. 35. Configuration beyond Java EE 828.03.2017 35 Remote configuration !
  36. 36. Configuration beyond Java EE 828.03.2017 36 ● Configuration is read from remote source, e.g. ● Etcd cluster ● Consul cluster ● Any Web URL ● ... Remote PropertySources Service Location Layer Configuration Cluster <dependency>     <groupId>org.apache.tamaya.ext</groupId>     <artifactId>tamaya­etcd</artifactId>     <version>...</version> </dependency>
  37. 37. Configuration beyond Java EE 828.03.2017 37 Easy Configuration: „Meta“-Configuration !
  38. 38. Configuration beyond Java EE 828.03.2017 38 ● Configuration that configures configuration ● E.g. at META­INF/tamaya­config.xml ● Allows easy and quick setup of your configuration environment ● Allows dynamic enablement of property sources ● ... Meta-Configuration DRAFT !
  39. 39. Configuration beyond Java EE 828.03.2017 39 <configuration> <context> <context-param name="stage">DEV</context-param> </context> <sources> <source type="env-properties" enabled="${stage=TEST || stage=PTA || stage=PROD}" ordinal="200"/> <source type="sys-properties" /> <source type="file"> <observe period="20000">true</observe> <location>./config.json</location> </source> <source type="resources" multiple="true"> <multiple>true</multiple> <location>/META-INF/application-config.yml</location> </source> <source type="ch.mypack.MyClassSource"> <locale>de</locale> </source> <source type="includes" enabled="${context.cstage==TEST}"> <include>TEST.properties</include> </source> </sources> </configuration> DRAFT !
  40. 40. Configuration beyond Java EE 828.03.2017 40 Property resolution... java.home=/usr/lib/java compiler=${ref:java.home}/bin/javac <dependency>     <groupId>org.apache.tamaya.ext</groupId>     <artifactId>tamaya­resolver</artifactId>     <version>...</version> </dependency>
  41. 41. Configuration beyond Java EE 828.03.2017 41 Resource expressions… public class MyProvider extends AbstractPathPropertySourceProvider{   public MyProvider(){     super(“classpath:/META­INF/config/**/*.properties“);   }   @Override   protected Collection<PropertySource> getPropertySources(URL url) {       // TODO map resource to property sources       return Collections.emptySet();   } } <dependency>     <groupId>org.apache.tamaya.ext</groupId>     <artifactId>tamaya­resources</artifactId>     <version>...</version> </dependency>
  42. 42. Configuration beyond Java EE 828.03.2017 And more: a topic on its own! 42 ● Tamaya-spi-support: Some handy base classes to implement SPIs ● Tamaya-functions: Functional extension points (e.g. remapping, scoping) ● Tamaya-events: Detect and publish ConfigChangeEvents ● Tamaya-optional: Minimal access layer with optional Tamaya support ● Tamaya-filter: Thread local filtering ● Tamaya-usagetracker: Tracking use and stats for configuration consumption ● Tamaya-validation*: Configuration Documentation and Validation ● Format Extensions: yaml, json, ini, … including formats-SPI ● Integrations with Vertx, CDI, Spring, OSGI*, Camel, etcd, Consul ● Tamaya-mutable-config: Writable ConfigChangeRequests ● Tamaya-metamodel*: Configuration Meta-Model ● Tamaya-collections*: Collection Support ● Tamaya-resolver: Expression resolution, placeholders, dynamic values ● Tamaya-resources: Ant styled resource resolution •... * experimental
  43. 43. Configuration beyond Java EE 828.03.2017 Demo Adoption Area: We 13:00h (Community Hall)
  44. 44. Configuration beyond Java EE 828.03.2017 Summary
  45. 45. Configuration beyond Java EE 828.03.2017 Summary 45 ● Work on config JSR for a EE 8 has been stopped by Oracle ● Community work is done in Microprofile.io and ASF ● Microprofile API is very minimal, but will evolve. ● Apache Tamaya provides most features you will ever need and supports all major runtimes.
  46. 46. Configuration beyond Java EE 828.03.2017 46 You like it ?
  47. 47. Configuration beyond Java EE 828.03.2017 47 „It is your turn !“ ● Use it ● Evangelize it ● Join the force!
  48. 48. Configuration beyond Java EE 828.03.2017 Links ● Project Page: http://tamaya.incubator.apache.org ● Twitter: @tamayaconfig ● Blog: http://javaeeconfig.blogspot.com ● Presentation by Mike Keith on JavaOne 2013: https://oracleus.activeevents.com/2013/connect/sessionDetail.ww?SESSION_ID=7755 ● Apache Deltaspike: http://deltaspike.apache.org ● Java Config Builder: https://github.com/TNG/config-builder ● Apache Commons Configuration: http://commons.apache.org/proper/commons-configuration/ ● http://microprofile.io ● Microprofile Config API source: https://github.com/eclipse/microprofile-config 48
  49. 49. Configuration beyond Java EE 828.03.2017 Q&A 49 Thank you! @atsticks anatole@apache.org Anatole Tresch Trivadis AG Principal Consultant Twitter/Google+: @atsticks anatole@apache.org anatole.tresch@trivadis.com

×