64
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

Configuration for Java EE and the Cloud

Embed Size (px)

Citation preview

Page 1: Configuration for Java EE and the Cloud

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

Page 2: Configuration for Java EE and the Cloud

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.

Page 3: Configuration for Java EE and the Cloud

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

Page 4: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 4

Introduction

Page 5: Configuration for Java EE and the Cloud

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

Page 6: Configuration for Java EE and the Cloud

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

Page 7: Configuration for Java EE and the Cloud

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

Page 8: Configuration for Java EE and the Cloud

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

Page 9: Configuration for Java EE and the Cloud

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

Page 10: Configuration for Java EE and the Cloud

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

Page 11: Configuration for Java EE and the Cloud

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

Page 12: Configuration for Java EE and the Cloud

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

Page 13: Configuration for Java EE and the Cloud

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

Page 14: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 14

DZone and Java EE Guardians Survey Results

Page 15: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 15

Problem Definition

Page 16: Configuration for Java EE and the Cloud

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?

Page 17: Configuration for Java EE and the Cloud

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

Page 18: Configuration for Java EE and the Cloud

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

Page 19: Configuration for Java EE and the Cloud

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

Page 20: Configuration for Java EE and the Cloud

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

Page 21: Configuration for Java EE and the Cloud

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

Page 22: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 22

JSR Proposal

Page 23: Configuration for Java EE and the Cloud

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

Page 24: Configuration for Java EE and the Cloud

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

Page 25: Configuration for Java EE and the Cloud

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

Page 26: Configuration for Java EE and the Cloud

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

Page 27: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 27

JSR Features (Java EE 8)

Page 28: Configuration for Java EE and the Cloud

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);

Page 29: Configuration for Java EE and the Cloud

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);

Page 30: Configuration for Java EE and the Cloud

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

Page 31: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 31

Layering and Overrides

Page 32: Configuration for Java EE and the Cloud

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)

Page 33: Configuration for Java EE and the Cloud

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

Page 34: Configuration for Java EE and the Cloud

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

Page 35: Configuration for Java EE and the Cloud

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();

Page 36: Configuration for Java EE and the Cloud

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();

Page 37: Configuration for Java EE and the Cloud

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>

Page 38: Configuration for Java EE and the Cloud

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>

Page 39: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 39

JSR Features (Java EE Next)

Page 40: Configuration for Java EE and the Cloud

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

Page 41: Configuration for Java EE and the Cloud

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>

Page 42: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 42

ImmutabilityMutable Immutable

Page 43: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 43

Dynamic Configuration• Polling framework• Expressions• Property Resolvers• Configuration Context

Page 44: Configuration for Java EE and the Cloud

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();

Page 45: Configuration for Java EE and the Cloud

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

Page 46: Configuration for Java EE and the Cloud

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>

Page 47: Configuration for Java EE and the Cloud

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)

Page 48: Configuration for Java EE and the Cloud

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>

Page 49: Configuration for Java EE and the Cloud

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>

Page 50: Configuration for Java EE and the Cloud

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);

Page 51: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 51

Sample Use Case

Page 52: Configuration for Java EE and the Cloud

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

Page 53: Configuration for Java EE and the Cloud

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

Page 54: Configuration for Java EE and the Cloud

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

Page 55: Configuration for Java EE and the Cloud

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

Page 56: Configuration for Java EE and the Cloud

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)

Page 57: Configuration for Java EE and the Cloud

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

Page 58: Configuration for Java EE and the Cloud

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

Page 59: Configuration for Java EE and the Cloud

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

Page 60: Configuration for Java EE and the Cloud

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

Page 61: Configuration for Java EE and the Cloud

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

Page 62: Configuration for Java EE and the Cloud

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.

Page 63: Configuration for Java EE and the Cloud

Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 63

Q & A

Page 64: Configuration for Java EE and the Cloud