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 for Java EE and the Cloud

447 views

Published on

In the modern world, where apps consist of microservices and are deployed in a cloud, developers are facing many issues related to apps config. How to deploy an app in different environments without cracking its package. How to apply configuration for deployed instances of an app without redeployment. How an app can be notified if some configuration properties changes. This session introduces a standardization effort tasked with solving these problems by defining a Java EE config service. Such a service is aimed at the cloud and provides the ability to create one or more configurations that are independent of and decoupled from apps using them. The session describes how such a service fits into the Java EE family and integrates with other Java EE frameworks.

Published in: Software
  • Be the first to comment

Configuration for Java EE and the Cloud

  1. 1. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Configuration for Java EE and the Cloud Dmitry Kornilov dmitry.kornilov@oracle.com @m0mus September 21, 2016
  2. 2. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The 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. 2
  3. 3. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Program Agenda Introduction Problem Definition JSR Proposal & Features Sample Use Case Q & A 1 2 3 4 3 5
  4. 4. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Introduction 4
  5. 5. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 5
  6. 6. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 6
  7. 7. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 7
  8. 8. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 8
  9. 9. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 9
  10. 10. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 10
  11. 11. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 11
  12. 12. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 12
  13. 13. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 13
  14. 14. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 14 DZone and Java EE Guardians Survey Results
  15. 15. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Problem Definition 15
  16. 16. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | What is Configuration? 16 Application server setup? Runtime parameters? Deployment descriptors? Parameters of used frameworks? Deployment scripts? Used resources?
  17. 17. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Problems • Lack of standard configuration API • Configuring multiple instances • Deploying on different environments • Change configuration without redeployment • Configuration of decoupled microservices 17
  18. 18. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Problems • Lack of standard configuration API • Configuring multiple instances • Deploying on different environments • Change configuration without redeployment • Configuration of decoupled microservices 18
  19. 19. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Problems • Lack of standard configuration API • Configuring multiple instances • Deploying on different environments • Change configuration without redeployment • Configuration of decoupled microservices 19
  20. 20. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Problems • Lack of standard configuration API • Configuring multiple instances • Deploying on different environments • Change configuration without redeployment • Configuration of decoupled microservices 20
  21. 21. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Problems • Lack of standard configuration API • Configuring multiple instances • Deploying on different environments • Change configuration without redeployment • Configuration of decoupled microservices 21
  22. 22. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | JSR Proposal 22
  23. 23. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Configuration Definition • Application centric • Not modifiable by application • Consists of key/value pairs • Keys and values are strings • Flat structure 23
  24. 24. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 24
  25. 25. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 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 25 Java EE 8 • Optional configuration descriptor • Dynamic configuration • Integration with other Java EE frameworks Java EE Next
  26. 26. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Roadmap 26 Submit JSR Review JSR Expert Group Formation Sep 2016 Oct 2016 Nov 2016 Dec 2016 Jan 2017 Feb 2017 Mar 2017 Apr 2017 May 2017 June 2017 July 2017 Aug 2017 Sep 2017 Early Draft Public Draft Proposed Final Draft Final Release
  27. 27. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | JSR Features (Java EE 8) 27
  28. 28. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | API 28 a=JavaOne b=9 c=2016 Config config = ConfigProvider.getConfig(); // Returns "JavaOne" String foo = config.getProperty("a"); // Returns string "9" String fooBar = config.getProperty("b"); // Returns null String notExists = config.getProperty("not.exist"); // Returns string "default" String notExistsDefault = config.getProperty("not.exist","default"); // Returns number 2016 Long fooBarBaz = config.getProperty("c", Long.class);
  29. 29. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Converters 29 • 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);
  30. 30. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Configuration Sources 30 • 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
  31. 31. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Layering and Overrides 31
  32. 32. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Default Configuration Sources 32 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)
  33. 33. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Defining Configuration Sources 33 • Using config.sources runtime parameter • Using API • Using config-sources.xml file
  34. 34. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Customizing Configuration Sources 34 Using 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 199 java –jar my.jar –Dconfig.source=http://shared/global.xml,/conf/my.json
  35. 35. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Customizing Configuration Sources 35 Using API Config 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();
  36. 36. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | config-sources.xml 36 • 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();
  37. 37. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Sample config-sources.xml 37 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>
  38. 38. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Sample config-sources.xml 38 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>
  39. 39. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | JSR Features (Java EE Next) 39
  40. 40. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Integration With Other Java EE Frameworks • Read configuration from Java EE Config • Store configuration as part of whole application configuration • Use standard API 40 Java EE Config Application Configuration Application JPA Configuration JAX-RS Configuration
  41. 41. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Configuration Descriptor 41 • 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>
  42. 42. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Immutability 42 Mutable Immutable
  43. 43. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Dynamic Configuration 43 • Polling framework • Expressions • Property Resolvers • Configuration Context
  44. 44. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Polling 44 // Defining polling using API Config 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();
  45. 45. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Polling 45 // Defining polling using API Config 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
  46. 46. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Polling 46 <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>
  47. 47. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Polling 47 <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)
  48. 48. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Expressions 48 • 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>
  49. 49. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Property Resolvers 49 • 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>
  50. 50. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Configuration Context 50 • 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);
  51. 51. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Sample Use Case 51
  52. 52. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Blacklist Service Financial Records Service Public Registry DBBlacklist Service Financial Records Service Public Registry DB Client Rating Confidential – Oracle Internal/Restricted/Highly Restricted 52 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
  53. 53. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Client Rating Confidential – Oracle Internal/Restricted/Highly Restricted 53 Customer 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
  54. 54. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Client Rating Confidential – Oracle Internal/Restricted/Highly Restricted 54 cust-db rating-url records-count log-level blacklist-url findata-url log-level Customer Service Rating ServiceDB
  55. 55. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Client Rating Confidential – Oracle Internal/Restricted/Highly Restricted 55 <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
  56. 56. 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_db rating-url=http://ratinghost/ratingservice" blacklist-url=http://blhost/blservice findata-url=http://findatahost/ratingservice log-level=INFO records-count=30 log-level=WARN Global configuration (global.properties) Microservice configuration (cust_svc.properties) Microservice configuration (rating_svc.properties) Override only for iOS application (cust_ios.properties)
  57. 57. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Client Rating Confidential – Oracle Internal/Restricted/Highly Restricted 57 <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
  58. 58. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Client Rating Confidential – Oracle Internal/Restricted/Highly Restricted 58 global.properties rating_svc.propertiescust_svc.propertiescust_ios.properties Customer Service Rating ServiceDB
  59. 59. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Cloud Configuration Service Idea Confidential – Oracle Internal/Restricted/Highly Restricted 59 Customer Service Rating Service DB
  60. 60. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Cloud Configuration Service 60 • 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
  61. 61. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Next Steps • Take the survey – http://glassfish.org/survey • Send technical comments to – users@javaee-spec.java.net • 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 61
  62. 62. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Where to Learn More at JavaOne 62 Session 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.
  63. 63. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | Q & A 63

×