configuration with apache tamaya
TRANSCRIPT
![Page 1: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/1.jpg)
Anatole TreschTrivadis AG@atsticks
![Page 2: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/2.jpg)
Apache TamayaConfigure Everything...
![Page 3: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/3.jpg)
Anatole Tresch
● Principal Consultant, Trivadis AG (Switzerland)● Star Spec Lead JSR 354● Technical Architect, Lead Engineer● PPMC Member Apache Tamaya
● Twitter/Google+: @atsticks● [email protected]● [email protected]● JUG Switzerland
3
Bio
![Page 4: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/4.jpg)
Agenda
4
● Introduction
● What to configure?
● Apache Tamaya
● Core Concepts
● Extensions
● Demo & Outlook
![Page 5: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/5.jpg)
5
Introduction
![Page 6: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/6.jpg)
6
● 2012: Configuration was voted an important aspect for Java EE 8
● 2013: ● Setup of Java EE Configuration JSR failed● Standardization on SE Level did not have enough momentum
● BUT:● Configuration is a crucial cross cutting concern● There is no (really NO!) defacto standard● Reinventing the wheel is daily business
History of Apache Tamaya
![Page 7: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/7.jpg)
The People behind Tamaya
7
• John D. Ament (Mentor)
• David Blevins (Champion)
• Werner Keil
• Gerhard Petracek (Mentor)
• Mark Struberg (Mentor)
• Anatole Tresch
• Oliver B. Fischer
• ...
••
![Page 8: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/8.jpg)
The Objectives of Apache Tamaya
8
● Define a common API for accessing configuration● Minimalistic● Flexible, pluggable and extendible
● Compatible with Java 7 and beyond
● Provide a reference implementation
● Provide Extension Modules for additional features
● Build up a community
● If possible, create a Standard!
••
![Page 9: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/9.jpg)
What to configure?
![Page 10: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/10.jpg)
What to configure?
10
● Most complex question ever!
● Divergent views● Servers, Containers, Machines, Clusters, ...● Parameters of a runtime (staging, localization etc.)● Deployments, Network, ...● Technology-specific components (beans, wirings etc.)● Resources (data sources, message queues, services etc.)● Descriptive or imperative style
● Different granularities, varying levels of applicability, different formats …
![Page 11: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/11.jpg)
How to configure?
11
● Format
● Storage
● Lifecycle and versioning
● Security
● Distribution
● Consistency
![Page 12: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/12.jpg)
...
12
![Page 13: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/13.jpg)
Use Cases
![Page 14: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/14.jpg)
UC: Access Configuration Similarly
14
Apache Tamaya Config
Unified Common API
MicroService
Container
IaaS
PaaS
Cache SaaS
Build-Tool
● Any Location● Any Format● Any Policy
Extension Points:SPI
![Page 15: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/15.jpg)
UC: Reduce Redundancy
15
Bar
Foo
Foo Configuration:Service.host.ip=192.168.1.10Service.stage=testService.param=paramValue
Redundant!
File 1
File 2
TamayaConfiguration
Bar Configuration:bar.host.ip=${env:HOST_IP}bar.stage=${env:STAGE}bar.param=paramValue
Cache Configuration:Cache.host.ip=192.168.1.10Cache.stage=testCache.param=cacheValue
TamayaConfiguration
Foo Configuration:foo.host.ip=${env:HOST_IP}foo.stage=${env:STAGE}foo.param=cacheValue
TamayaConfiguration
TamayaConfiguration
![Page 16: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/16.jpg)
UC: Convention over Configuration
16
Foo Configuration:bar.host.ip=${cfg:env.host.ip}bar.stage=${cfg:env.stage}bar.param=paramValue
Cache Configuration:foo.host.ip=${cfg:env.host.ip}foo.stage=${cfg:env.stage}foo.param=cacheValue
Defaults:default.host.ip=${env:HOST_IP}default.stage=${env:STAGE}
Bar
Foo
TamayaConfiguration
TamayaConfiguration
![Page 17: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/17.jpg)
UC: Pluggable Config Backends
Classic:
Apache Tamaya Configuration
17
Distributed: ZooKeeper Etcd ...
Classic Policy(PropertySources)
Myproject/bin/...Myproject/conf/server.xmlMyproject/conf/cluster.xmlMyproject/conf/security.xmlMyproject/lib/......
Remote Policy(PropertySources)
???
Unified API for configuration access
Policies can be provided as jar-artifacts separately
Additional benefits: config documentation
Your Project
![Page 18: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/18.jpg)
UC: Enterprise Integration
18
Company X:Config SOAP
Myproject/bin/...Myproject/conf/server.xmlMyproject/conf/cluster.xmlMyproject/conf/security.xmlMyproject/lib/......
Company Z:Config Rest
Company Y:etcd
Company A:Legacy Config
Tamaya Configuration Classic Policy
(PropertySources)Config Integration(PropertySources)
dns etcd REST Java EE ...
![Page 19: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/19.jpg)
19
Bar
Foo
TamayaConfiguration
TamayaConfiguration
Locations: file:${filedir} classpath:META-INF/defaults/ configuration.*
classpath:META-INF/${STAGE}/ configuration.*
url:http://myserver.int/cfg System properties Env. Properties
Formats: properties xml json yaml
Config Policy
<implements>
Define, implement and distribute a CompanyWide Configuration Policy
Policy
Policy<implements>
UC: Enforceable Policies
![Page 20: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/20.jpg)
20
Configuration[Group, size: 8: >> Section: a.test.existing >> Parameter: a.test.existing.aParam, required: true >> Parameter: a.test.existing.optionalParam >> Parameter: a.test.existing.aABCParam, expression: [ABC].* >> Section: a.test.notexisting >> Parameter: a.test.notexisting.aParam, required: true >> Parameter: a.test.existing.aABCParam2, expression: [ABC].* >> Section: a.b.c.aRequiredSection.optional-subsection, >> Parameter: MyNumber, >> Section: a.b.c, >> Section: a.b.c.aRequiredSection.nonempty-subsection, >> Section: a.b.c.aRequiredSection - Parameter: a.b.c.aRequiredSection.subsection.param00,
Config Documentation
Tamaya allows to validate and document the configurationhooks used throughout your system!
UC: Documentation
Config ValidationMISSING: a.test.notexisting.aParam (Parameter), ERROR: a.test.existing.aABCParam2 (Parameter) -> Config value not matching expression: [ABC].*, was MMMMISSING: a.params2 (Parameter),MISSING: a.b.c.aRequiredSection.subsection.param1 (Parameter), UNDEFINED: JAVA_HOME (Parameter)UNDEFINED: SESSION_MANAGER (Parameter)[...]
![Page 21: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/21.jpg)
21
● Stop Reinventing the wheel
● Stay Focused on what to configure, not how!
● Reduce Redundancies and Inconsistencies
● Document your configuration options
● Integrate with Company Infrastructure („DevOps“)
● Decouple your configuration backends
Summary: Why we need Tamaya?
● Manage Config like APIs !
![Page 22: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/22.jpg)
The API
22
![Page 23: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/23.jpg)
Let's start simple!
23
● Add dependency org.apache.tamaya:core: 0.2-incubating (not yet released)
● Add Config to META-INF/javaconfiguration.properties
Configuration config = ConfigurationProvider.getConfiguration();
String name = config.getOrDefault("name", "John");int ChildNum = config.get("childNum", int.class);
![Page 24: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/24.jpg)
24
public interface Configuration{
String get(String key); String getOrDefault(String key, String defaultValue);
<T> T get(String key, Class<T> type); <T> T get(String key, TypeLiteral<T> type); <T> T getOrDefault(String key, Class<T> type, T defaultValue); <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue);
Map<String,String> getProperties();
// Functional Extension Points Configuration with(ConfigOperator operator): <T> T query(ConfigQuery<T> query);}
Configuration Interface
![Page 25: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/25.jpg)
Tamaya Design in 60 Seconds...
25
1.Configuration = ordered list of PropertySources
2.Properties found are combined using a CombinationPolicy
3.Raw properties are filtered by PropertyFilter4.For typed access PropertyConverters
have to do work5.Extensions add more features
(discussed later)6.Lifecycle is controlled by the ServiceContextManager
ConfigurationContext
PropertyFilters
PropertySource
PropertySource
PropertySource
PropertySource
Configuration
Com
bina
tionP
olic
yPropertyProviders<provides>
PropertyConverter
![Page 26: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/26.jpg)
SPI: PropertySource PropertySourceProvider
public interface PropertySource { static final String TAMAYA_ORDINAL = "tamaya.ordinal";
String getName(); int getOrdinal(); String get(String key); Map<String, String> getProperties();}
public interface PropertySourceProvider { Collection<PropertySource> getPropertySources();}
![Page 27: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/27.jpg)
Overriding Explained
27
#default ordinal = 0 name=Benjamin childNum=0 family=Tresch
#override ordinal tamaya.ordinal=10 name=Anatole childNum=3
tamaya.ordinal=10 name=Anatole childNum=3 family=Tresch
![Page 28: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/28.jpg)
CombinationPolicy
28
list=a,b,c _list.collection-type=List
tamaya.ordinal=10 list=aa,bb
tamaya.ordinal=10 list=aa,bb,a,b,c _list.collection-type=List
![Page 29: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/29.jpg)
There is more! - Extension Modules
29
![Page 30: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/30.jpg)
Extensions: a topic on its own!
30
•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-inject-api: Tamaya Configuration Injection Annotations•Tamaya-inject: Configuration Injection and Templates SE Implementation (lean, no CDI)•Tamaya-resolver: Expression resolution, placeholders, dynamic values•Tamaya-resources: Ant styled resource resolution•Format Extensions: yaml*, json, ini, … including formats-SPI•Integrations with CDI, Spring, OSGI, Camel, etcd•Tamaya-classloader-support: Managing Tamaya Services within Classloading Hierarchies•Tamaya-mutable-config: Writable ConfigChangeRequests•Tamaya-server: REST/JSON Configuration Server•Tamaya-remote: Integrate Tamaya Server resources as PropertySource•Tamaya-model*: Configuration Model and Auto Documentation•Tamaya-collections*: Collection Support•... * work in progress
![Page 31: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/31.jpg)
Planned Features
31
● Java EE: Configuring EE, where possible
● More Integrations:
● Commons-config (currently in experimental stage)● Additional Backends: Consul, Zookeeper,
ElasticSearch, Redis, …● ...
● Runtime Integrations:● Vertx● Docker?● ...
● „We are looking for committers!“
![Page 32: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/32.jpg)
Example: Configuration Injection
32
@ConfiguredType(defaultSections=”com.mycomp.tenantAdress”)public final class MyTenant{
private String name;
@ConfiguredProperty( defaultValue=”2000”) private long customerId;
@ConfiguredProperty(keys={ ”privateAddress”,”businessAdress”, ”[my.qualified.adress]” }) private String address; ...}
MyTenant t = new MyTenant();ConfigurationInjection .getConfigurationInjector() .configure(t);
MyTenant t = new MyTenant();ConfigurationInjection .getConfigurationInjector() .configure(t);
@RequestScopedpublic class MyClass{ @Inject private MyTenant t; …}
@RequestScopedpublic class MyClass{ @Inject private MyTenant t; …}
![Page 33: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/33.jpg)
Configuration Template
33
@ConfiguredType(defaultSections=”com.mycomp.tenantAdress”)public interface MyTenant{
public String getName();
@ConfiguredProperty( defaultValue=”2000”) public long getCustomerId();
@ConfiguredProperty(keys={ ”privateAddress”,”businessAdress”, ”[my.qualified.adress]” }) public String getAddress();
}
MyTenant t =ConfigurationInjection .getConfigurationInjector() .createTemplate(MyTenant.class);
MyTenant t =ConfigurationInjection .getConfigurationInjector() .createTemplate(MyTenant.class);
![Page 34: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/34.jpg)
Demo
DEMO TIME
34
![Page 35: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/35.jpg)
Demo Setup - Microservices
35
● What you will see:
● - Starting with a simple config client
● - Adding configuration based user/password auth
1)- Local Properties Only
2)- Etcd d Backend
• - Starting with DropWizard
• - Adding Spring Boot GET /config (dropexample.HelloWorldResource) GET /hello (dropexample.HelloWorldResource) GET /login (dropexample.LoginResource) POST /login (dropexample.LoginResource) GET /user (dropexample.LoginResource)
GET /config (dropexample.HelloWorldResource) GET /hello (dropexample.HelloWorldResource) GET /login (dropexample.LoginResource) POST /login (dropexample.LoginResource) GET /user (dropexample.LoginResource)
![Page 36: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/36.jpg)
Summary
36
Apache Tamaya Provides • A Complete thread- and type-safe Configuration API compatible with all commonly used runtimes
• A simple, but extendible design
• A myriad of extensions
• A small footprint
• Remote Support
•Almost „Swiss Made“
![Page 37: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/37.jpg)
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/ ● Jfig: http://jfig.sourceforge.net/ ● Carbon Configuration: http://carbon.sourceforge.net/modules/core/docs/config/Usage.html ● Comparison on Carbon and Others: http://www.mail-archive.com/[email protected]/msg37597.html ● Spring Framework: http://projects.spring.io/spring-framework/● Owner: http://owner.aeonbits.org/
37
![Page 38: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/38.jpg)
Q&A
38
Thank you!Anatole TreschTrivadis AGPrincipal ConsultantTwitter/Google+: @atsticks [email protected] [email protected]
![Page 39: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/39.jpg)
API Entry Point: ConfigurationProvider
42
public class ConfigurationProvider{
public static Configuration getConfiguration(); public static ConfigurationContext getConfigurationContext();
public static ConfigurationContextBuilder getConfigurationContextBuilder() public static void setConfigurationContext( ConfigurationContext context);}
![Page 40: Configuration with Apache Tamaya](https://reader034.vdocument.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c95/html5/thumbnails/40.jpg)
Configuration vs Components
46
Component X
Component Y
<dependency>
Configuration
<dependency> Components: Behaviour and state Code Dynamic Not serializalbe Inheritance Usage
Configuration: Descriptive Data Key, value pairs Static (Relatively) Serializable Overriding References