Configure Your Projects with Apache Tamaya
-
Upload
anatole-tresch -
Category
Technology
-
view
694 -
download
0
Transcript of Configure Your Projects with Apache Tamaya
![Page 1: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/1.jpg)
Anatole Tresch & Werner KeilTrivadis AG@atsticks @wernerkeil
![Page 2: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/2.jpg)
Apache TamayaConfiguration Management
![Page 3: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/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, Zurich Java Community
3
Bio
![Page 4: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/4.jpg)
Werner Keil
● Consultant – Coach● Creative Cosmopolitan● Open Source Evangelist● Software Architect● JCP EC Member● Tamaya Committer● Java EE | DevOps Guy …
● Twitter/Google+: @wernerkeil● [email protected]
4
Bio
![Page 5: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/5.jpg)
Agenda
5
● General Infos
● What is Configuration?
● Use Cases
● Apache Tamaya
● Core Concepts
● Extensions
● Outlook
![Page 6: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/6.jpg)
6
General Infos
![Page 7: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/7.jpg)
7
● 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 8: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/8.jpg)
The People behind Tamaya
8
• John D. Ament (Mentor)
• David Blevins (Champion)
• Werner Keil
• Gerhard Petracek (Mentor)
• Mark Struberg (Mentor)
• Anatole Tresch
• Oliver B. Fischer
• ...
••
![Page 9: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/9.jpg)
The Objectives of Apache Tamaya
9
● Define a common API for accessing configuration● Minimalistic, also fits into ME● Flexible, pluggable and extendible design● support functional programming style
● Be compatible with Java 7 and beyond
● Provide a reference implementation
● Provide Extension Modules for Additional Features
● If possible, create a Standard!
••
![Page 10: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/10.jpg)
What is Configuration?
![Page 11: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/11.jpg)
What people think is configuration?
11
● Many different interested stakeholders
● Many things to configure
● Divergent views● Setup for a server environment● Parameters of a runtime (staging, localization etc.)● Deployment descriptors● Technology-specific components (beans, wirings etc.)● Resource-specific settings (data sources, message queues etc.)● Dynamic scripting facility, Different scopes (global, ear, app, …)
● Different granularities, varying levels of applicability, Different formats …
![Page 12: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/12.jpg)
What we think is configuration
12
Component X
Component Y
<dependency>
Configuration
<dependency> Components: Behaviour and state Transitive Deps Scopes Code Dynamic Not serializalbe
Configuration: Data, Value Types Transitive Deps Scopes Key, value pairs Static Serializable
![Page 13: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/13.jpg)
Use Cases
![Page 14: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/14.jpg)
UC: Access Configuration Similarly
14
Configuration
APIAPI
MicroService
Container
IaaS
PaaS
Cache SaaS
Build-Tool
● Any Location● Any Format● Any Policy
SPI
![Page 15: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/15.jpg)
UC: Reduce Redundancy
15
Service Foo
Cache
Foo Configuration:Service.host.ip=192.168.1.10Service.stage=testService.param=paramValue
Redundant!
File 1
File 2
TamayaConfiguration
Foo Configuration:Service.host.ip=${env:HOST_IP}Service.stage=${env:STAGE}Service.param=paramValue
Cache Configuration:Cache.host.ip=192.168.1.10Cache.stage=testCache.param=cacheValue
TamayaConfiguration
Cache Configuration:Cache.host.ip=${env:HOST_IP}Cache.stage=${env:STAGE}Cache.param=cacheValue
TamayaConfiguration
TamayaConfiguration
![Page 16: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/16.jpg)
UC: Convention over Configuration
16
Foo Configuration:Service.host.ip=${cfg:env.host.ip}Service.stage=${cfg:env.stage}Service.param=paramValue
Cache Configuration:Cache.host.ip=${cfg:env.host.ip}Cache.stage=${cfg:env.stage}Cache.param=cacheValue
Defaults:env.host.ip=${env:HOST_IP}env.stage=${env:STAGE}
Service Foo
Cache
TamayaConfiguration
TamayaConfiguration
![Page 17: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/17.jpg)
UC: Pluggable Config Backends
Classic:
Tamaya Configuration
17
Distributed: ZooKeeper Etcd ...
Classic Policy(PropertySources)
Myproject/bin/...Myproject/conf/server.xmlMyproject/conf/cluster.xmlMyproject/conf/security.xmlMyproject/lib/......
Unified Config API
Remote Policy(PropertySources)
???
Unified API for configuration access
Policies can be provided as jar-artifacts separately
Additional benefits: config documentation
Your Project
![Page 18: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/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)
Unified Config API
Config Integration(PropertySources)
Your Project
![Page 19: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/19.jpg)
19
Service Foo
Cache
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 CompanyWide Configuration Policy
Policy
Policy<implements>
UC: Enforceable Policies
![Page 20: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/20.jpg)
20
● Reinventing the wheel is daily business, leading to
● Higher Efforts in Enterprise Integration
● Configuration Redundancies and Inconsistencies
● Unclear or Complex Handling when remote Configuration should be
supported as well
● Make Projects Integration Raedy with Company Infrastructure
● Make your Configuration Backends Pluggable
Summary: Why we need Tamaya?
![Page 21: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/21.jpg)
The API
21
![Page 22: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/22.jpg)
Let's start simple!
22
● Add dependency org.apache.tamaya:core:1.0-incubating
● Add Config to META-INF/javaconfiguration.properties
● Use it!
Configuration config = ConfigurationProvider.getConfiguration();
String name = config.getOrDefault("name", "John");int ChildNum = config.get("childNum", int.class);
![Page 23: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/23.jpg)
ConfigurationProvider
23
public class ConfigurationProvider{
public static Configuration getConfiguration(); public static ConfigurationContext getConfigurationContext();
public static ConfigurationContextBuilder getConfigurationContextBuilder() public static void setConfigurationContext( ConfigurationContext context);}
![Page 24: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/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
![Page 25: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/25.jpg)
Core Concepts
25
● Configuration provides properties ● built up by an ordered list of PropertySources
● SPI● PropertyConverter● CombinationPolicy● PropertyFilter
● Extensions (discussed later)
ConfigurationContext
PropertyFilters
PropertySource
PropertySource
PropertySource
PropertySource
Configuration
Com
bina
tionP
olic
yPropertyProviders<provides>
PropertyConverter
![Page 26: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/26.jpg)
Overriding Basics
26
#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 27: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/27.jpg)
CombinationPolicy
27
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 28: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/28.jpg)
SPI: PropertySource PropertySourceProviderpublic 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 29: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/29.jpg)
Extension Modules
29
![Page 30: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/30.jpg)
Available Plugins
30
•Tamaya-inject: Configuration Injection and Templates
•Tamaya-resolver: Expression resolution, placeholders, dynamic values
•Tamaya-resources: Ant styled resource resolution
•Tamaya-format: Abstraction of a format, separating parsing from semantic mapping to
configuration
•Format Extensions: yaml*, json, ini, ...
•Tamaya-spring: Integration with Spring
•Tamaya-classloader-support: Managing Tamaya Services within Classloading Hierarchies
•Tamaya-cdi: Integration with CDI
•Tamaya-server: REST/JSON Configuration Server
•Tamaya-remote: Client PropertySource matching server component
•Tamaya-docs*: Configuration Documentation
•Tamaya-collections*: Collection Support
•...
* work in progress
![Page 31: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/31.jpg)
Planned Features
31
● Java EE: Configuring EE, where possible
● Karaf Integration
● Source Integrations:
● Commons-config
● Etcd
● Zookeeper
● ...
● Runtime Integrations:
● ???
![Page 32: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/32.jpg)
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: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/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: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/34.jpg)
Demo
DEMO
34
![Page 35: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/35.jpg)
Summary
35
Apache Tamaya Provides
• A Complete API based on Java SE 7, compatible with SE 6
• String key/value based thread-safe Configuration Model
• Support for Type-Safe Configuration Value Conversion
• Functional extension points
• Simple Filtering and Overrides
• Small footprint
• Extendible with plugins
![Page 36: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/36.jpg)
We need help
36
Apache Tamaya is great, but we need you...
• … using it!
• … asking for features!
• … envangelizing it!
• … loving it!
• … extending it!
• ...
![Page 37: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/37.jpg)
Links● 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: Configure Your Projects with Apache Tamaya](https://reader034.fdocuments.in/reader034/viewer/2022042723/5871429d1a28ab55588b4c93/html5/thumbnails/38.jpg)
Q&A
38
Thank you!Anatole TreschTrivadis AGPrincipal ConsultantTwitter/Google+: @atsticks [email protected] [email protected]