Date post: | 08-Jan-2017 |
Category: |
Software |
Upload: | dmitry-kornilov |
View: | 136 times |
Download: | 2 times |
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |
Configuration for Java EE and the Cloud
Dmitry Kornilov
[email protected]@m0mus
September 21, 2016
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 2
Safe Harbor StatementThe following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 3
Program Agenda
Introduction
Problem Definition
JSR Proposal & Features
Sample Use Case
Q & A
1
2
3
4
5
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 4
Introduction
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 5
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 6
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 7
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 8
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 9
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 10
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 11
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 12
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith on JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 13
History & Introduction• 2003 – Apache Commons Configuration• 2009 – Spring 3.0 • 2011 – Apache DeltaSpike• 2013 – Mike Keith at JavaOne• 2014 – Java EE 8 Survey• 2014 – Netflix Archaius• 2015 – Attempt to submit a JSR• 2015 – Apache Tamaya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 14
DZone and Java EE Guardians Survey Results
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 15
Problem Definition
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 16
What is Configuration?
Application server setup?Runtime parameters?
Deployment descriptors?Parameters of used frameworks?
Deployment scripts? Used resources?
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 17
Problems• Lack of standard configuration API• Configuring multiple instances• Deploying on different environments• Change configuration without
redeployment• Configuration of decoupled
microservices
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 18
Problems• Lack of standard configuration API• Configuring multiple instances• Deploying on different environments• Change configuration without
redeployment• Configuration of decoupled
microservices
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 19
Problems• Lack of standard configuration API• Configuring multiple instances• Deploying on different environments• Change configuration without
redeployment• Configuration of decoupled
microservices
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 20
Problems• Lack of standard configuration API• Configuring multiple instances• Deploying on different environments• Change configuration without
redeployment• Configuration of decoupled
microservices
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 21
Problems• Lack of standard configuration API• Configuring multiple instances• Deploying on different environments• Change configuration without
redeployment• Configuration of decoupled
microservices
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 22
JSR Proposal
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 23
Configuration Definition• Application centric• Not modifiable by application• Consists of key/value pairs• Keys and values are strings• Flat structure
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 24
Java EE Configuration• Unified API• Externalized configuration• Support of multiple configuration sources– Properties, xml and json formats support out of the box
• Layering and overrides• Optional configuration descriptor• Dynamic configuration• Integration with other Java EE frameworks
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 25
Java EE Configuration• Unified API• Externalized configuration• Support of multiple configuration sources– Properties, xml and json formats support out of the box
• Layering and overrides
Java EE 8
• Optional configuration descriptor• Dynamic configuration• Integration with other Java EE frameworks
Java EE Next
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 26
Roadmap
Submit JSR
Review JSRExpert Group Formation
Sep 2016
Oct2016
Nov2016
Dec2016
Jan2017
Feb2017
Mar2017
Apr2017
May2017
June2017
July2017
Aug2017
Sep2017
Early Draft
Public Draft
Proposed Final Draft
Final Release
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 27
JSR Features (Java EE 8)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 28
API
a=JavaOneb=9c=2016
Config config = ConfigProvider.getConfig();
// Returns "JavaOne"String foo = config.getProperty("a");
// Returns string "9"String fooBar = config.getProperty("b");
// Returns nullString notExists = config.getProperty("not.exist");
// Returns string "default"String notExistsDefault = config.getProperty("not.exist","default");
// Returns number 2016Long fooBarBaz = config.getProperty("c", Long.class);
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 29
Converters• Type safe access to values• Built-in converters for:– Primitive Wrappers– BigDecimal, BigInteger, URL, URI– Date, Calendar– java.time.*
public interface Converter<Target> { Target convert(String value);}
public class FooConverter implements Converter<Foo> {
public Foo convert(String value) { ... }}
Config cfg = ConfigProvider.builder() .withConverters(new FooConverter()) .build();
Foo foo = cfg.getProperty("foo", Foo.class);
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 30
Configuration Sources• Multiple configuration sources • Supported configuration sources:– System properties– Runtime parameters– File (Properties, xml, json)– Resource on a web server
• Pluggable architecture– Custom sources (like DB)
• Configuration sources are ordered
Java EE Config
XML JSONprop
DBweb
Application
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 31
Layering and Overrides
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 32
Default Configuration Sources
Java EE Config
• System properties (ordinal=400)• Environment properties (ordinal=300)• /META-INF/config.properties (ordinal=100)• /META-INF/config.xml (ordinal=100)• /META-INF/config.json (ordinal=100)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 33
Defining Configuration Sources• Using config.sources runtime parameter• Using API• Using config-sources.xml file
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 34
Customizing Configuration SourcesUsing config.sources runtime parameter
# Single file source with default ordinal (200)java –jar my.jar –Dconfig.source=/conf/myconfig.properties
# Web source with default ordinal (200)java –jar my.jar –Dconfig.source=http://shared/global.xml
# Two sources. Ordinals are 200 and 199java –jar my.jar –Dconfig.source=http://shared/global.xml,/conf/my.json
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 35
Customizing Configuration SourcesUsing APIConfig config = ConfigProvider.builder() .addSource(new EnvSource(), 300) .addSource(new FileSource("/cfg/config.properties"), 200) .addSource(new WebSource("http://localhost:8080/config.xml"), 100) .addSource(new MyCustomSource()) .build();
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 36
config-sources.xml• File with defined schema using to define configuration sources and their
metadata• Default location /META-INF/config-sources.xml• Can be placed outside of the application package• Define using runtime parameter
• Define using API
java –jar my.jar –Dconfig.sources=http://sharedhost/config-sources.xml
Config c = ConfigProvider.builder() .withSources("/cfg/config-sources.xml") .build();
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 37
Sample config-sources.xml Simple
With ordinals
<config-sources> <source>http://shared:8080/config.xml</source> <source>/cfg/myconf.json</source></config-sources>
<config-sources> <source ordinal="500">http://shared:8080/config.xml</source> <source ordinal="450">/cfg/myconf.json</source></config-sources>
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 38
Sample config-sources.xml Custom<config-sources> <source>http://shared:8080/config.xml</source> <source type="com.oracle.config.CloudConfig"> <user>user</user> <password>secret</password> </source></config-sources>
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 39
JSR Features (Java EE Next)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 40
Integration With Other Java EE Frameworks• Read configuration from
Java EE Config• Store configuration as part of
whole application configuration• Use standard API Java EE
Config
ApplicationConfiguration
Application
JPAConfiguration
JAX-RSConfiguration
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 41
Configuration Descriptor• File with defined format• Defines all configurable properties
and metadata• Optional• It’s not XML-Schema!
<config-descriptor> <property name="a"/> <property name="b" default=”valueB"/> <property name="c" mutable="false"/> <property name="d"/></config-descriptor>
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 42
ImmutabilityMutable Immutable
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 43
Dynamic Configuration• Polling framework• Expressions• Property Resolvers• Configuration Context
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 44
Polling
// Defining polling using APIConfig cfg = ConfigProvider.builder() .withSource(new FileSource("/cfg/config.xml"), 200, Duration.ofSeconds(30)) .withSource(new WebSource("http://shared/config.xml"), 100, Duration.ofMinutes(1)) .build();
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 45
Polling
// Defining polling using APIConfig cfg = ConfigProvider.builder() .withSource(new FileSource("/cfg/config.xml"), 200, Duration.ofSeconds(30)) .withSource(new WebSource("http://shared/config.xml"), 100, Duration.ofMinutes(1)) .build();
Ordinal Refresh IntervalLocation
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 46
Polling
<config-sources refresh-rate="300000">
<source ordinal="200" refresh-rate="30000">/cfg/config.xml</source>
<source ordinal="100" refresh-rate="60000">http://shared/config.xml</source>
</config-sources>
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 47
Polling
<config-sources refresh-rate="300000">
<source ordinal="200" refresh-rate="30000">/cfg/config.xml</source>
<source ordinal="100" refresh-rate="60000">http://shared/config.xml</source>
</config-sources>
Sources list refresh interval
(5 min)
Source 1 refresh interval (30 sec) Source 2 refresh
interval (1 min)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 48
Expressions• EL like expressions evaluated at runtime to a property value• Property substitution
• Conditional configuration sources
foo=${some.other.value}bar=${foo + 10}baz=${foo * bar}
<config-sources> <source>//cfg/config.properties</source> <source enabled=”${app==‘ios’}”> //cfg/cust_ios.properties </source> </config-sources>
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 49
Property Resolvers• Flexible mechanism allowing
executing user code in configuration expressions• Can be used to inject cloud
resources
rating.service.url=${eureka:rating.url}cust.db=${cloud:cust.db}
<config-sources> <resolvers> <resolver name=”cloud”> <class>com.example.CloudResolver</class> <username>user</username> <password>secret</password> </resolver> </resolvers> <!-- ... --> </config-sources>
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 50
Configuration Context• Allows application setting variables which can be used in configuration
expressions• Example: geographical zone, application type, etc.
<config-sources> <source>//cfg/config.properties</source> <source enabled=”${app==‘ios’}”> //cfg/cust_ios.properties </source> </config-sources>
Config config = ConfigProvider.getConfig();ConfigContext context = ConfigContext.builder().addProperty("app", "ios").build(); Long prop = config.getPropertyWithContext("prop", context);
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 51
Sample Use Case
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 52
Blacklist Service
Financial Records Service
Public Registry
DBBlacklist Service
Financial Records Service
Public Registry
DB
Client Rating
Customer Service Rating Service
• https://github.com/psplinakis/ClientRating• Consists of 4 microservices communicating to each other using RESTful API• Each microservice is developed by different team which define its
configuration and responsible for its deployment
DB
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 53
Client RatingCustomer
Service Rating ServiceDB
GET http://custhost/custservice/web/getCustomers
[ {cust_id: 1, rating: 9}, {cust_id: 2, rating: 5}] GET http://ratinghost/ratingservice/getRating/1
rating: 9
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 54
Client Rating
cust-dbrating-url records-countlog-level
blacklist-urlfindata-url log-level
Customer Service Rating ServiceDB
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 55
Client Rating
<config-descriptor> <context-property name=”app”/> <property name=”cust-db” mutable="false"/> <property name=”rating-url"/> <property name=”records-count" default=”100"/> <property name=”log-level" default=”INFO"/> </config-descriptor>
<config-descriptor> <property name=”blacklist-url”/> <property name=”findata-url"/> <property name=”log-level" default=”INFO"/> </config-descriptor>
Customer Service Rating ServiceDB
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. |
Client Rating<config-descriptor> <context-property name=”app”/> <property name=”cust-db” mutable="false"/> <property name=”rating-url"/> <property name=”records-count" default=”100"/> <property name=”log-level" default=”INFO"/> </config-descriptor>
<config-descriptor> <property name=”blacklist-url”/> <property name=”findata-url"/> <property name=”log-level" default=”INFO"/> </config-descriptor>
cust-db=mysql://dbhost:3306/cust_dbrating-url=http://ratinghost/ratingservice"
blacklist-url=http://blhost/blservicefindata-url=http://findatahost/ratingservicelog-level=INFO
records-count=30
log-level=WARNGlobal configuration (global.properties)
Microservice configuration (cust_svc.properties) Microservice configuration (rating_svc.properties)
Override only for iOS application (cust_ios.properties)
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 57
Client Rating
<config-sources> <source refresh-rate=”6000” enabled=”${app==‘ios’}”> //cfg/cust_ios.properties </source> <source> //cfg/cust_svc.properties </source> <source refresh-rate=”6000”> http://globalhost/global.properties </source></config-sources>
<config-sources> <source> //cfg/rating_svc.properties </source> <source refresh-rate=”6000”> http://globalhost/global.properties </source></config-sources>
Customer Service Rating ServiceDB
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 58
Client Rating
global.properties rating_svc.propertiescust_svc.propertiescust_ios.properties
Customer Service Rating ServiceDB
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Confidential – Oracle Internal/Restricted/Highly Restricted 59
Cloud Configuration Service IdeaCustomer
Service Rating Service
DB
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 60
Cloud Configuration Service• Service in the cloud• Distributed and high-available
configuration storage• Pluggable to Java EE Config• Integration with other cloud services• REST and web API• Versioning, history, security
Customer Service Rating Service
DB
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 61
Next Steps
• Take the survey– http://glassfish.org/survey
• Send technical comments to– [email protected]
• Join the JCP – come to Hackergarden in Java Hub– https://jcp.org/en/participation/membership_drive
• Join or track the JSRs as they progress– https://java.net/projects/javaee-spec/pages/Specifications
• Adopt-a-JSR– https://community.oracle.com/community/java/jcp/adopt-a-jsr
Give us your feedback
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 62
Where to Learn More at JavaOneSession Number Session Title Day / Time
CON7977 Java EE Next – HTTP/2 and REST Wednesday 1:00 p.m.CON6077 The Illusion of Statelessness Wednesday 4:30 p.m.CON 7981 JSF 2.3 Thursday 11:30 a.m.
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 63
Q & A