Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Project Helidon - Java Libraries for creating m...

Project Helidon - Java Libraries for creating microservices (Japanese)

Summarize project Helidon and some implementation tips.

Akihiro Nishikawa

December 17, 2018
Tweet

More Decks by Akihiro Nishikawa

Other Decks in Technology

Transcript

  1. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Project Helidon Akihiro Nishikawa Oracle Corporation Japan Java Libraries for Microservices 1
  2. Copyright © 2018, 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. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Program Agenda What’s Helidon? Demo Diving a little bit deeply... Helidon can also run on Custom JRE! Resources 1 2 3 4 5 3
  4. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    6 • Microframework • Functional Style • Reactive • Transparent • MicroProfile • Declarative Style • CDI, JAX-RS, JSON-P • Familiar to Java EE developers
  5. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    7 Java Microservice Frameworks Smaller Larger Spring Boot Microframeworks MicroProfile Based Open Liberty Full-Stack Dropwizard
  6. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    8 Architecture Helidon SE Netty WebServer Security Config Helidon MP CDI JAX-RS JSON-P
  7. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Eclipse MicroProfile • Java EE,!".#1($0*.) !-2016 • RedHatIBMTomitribePayara$%1' • ,!".#1($*.) !- • Java EE APIMicroProfile API  – JAX-RS, CDI, JSON-P, JSON-B – MP Config, Metrics, Health Check, Fault Tolerance, JWT Auth – Open API, OpenTracing, RestClient • +/&1 9 2.1 (2018/10/19)
  8. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Reactive WebServer •  BF7(D-?8BG A',7(<Flow API • Netty" • OpenTracing&$ Metrics"  • JAX-RS, JSON-P support • .D7D6#/>F9 Config • ! ?8B •  #8F32F0 • ?8B • !'5=8F9 •  10 Security • E • '*9;*D:E1+@A7( •  •  • %#=C;)4 – OIDC – JWT – Google Login Helidon SE
  9. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Helidon SE import io.helidon.webserver.Routing; import io.helidon.webserver.WebServer; public static void main(String[] args) { WebServer.create( Routing.builder() .get("/greet", (req, res) -> res.send("Hello World!")) .build()).start(); } Helidon MP import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; public class GreetService { @GET @Path("/greet") public String getMsg() { return "Hello World!"; } } 11 SE/MPHello World
  10. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    12 CDI ExtensionsPreview !!#&0.10.5 Helidon MP Helidon SE Microprofile 1.2 • WebServer, Config, Security • JSON-P • Metrics • OpenTracing • HTTP/2 (experimental) CDI Extensions MicroProfile ConfigCDI 2.0   #   CDI Extension$ " #%
  11. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

      • MicroProfile 2.x • Reactive HTTP Client • GraalVM  • Project Starter UI • Reactive storage (NoSQL, ADBA) • Open API • Eventing 13
  12. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Demo • Quickstart • Server config and startup • Basic Routing • Basic JSON handling • Docker Container Creation • Running on Kubernetes 15
  13. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    16 Archetype Helidon SE mvn archetype:generate -DinteractiveMode=false ¥ -DarchetypeGroupId=io.helidon.archetypes ¥ -DarchetypeArtifactId=helidon-quickstart-se ¥ -DarchetypeVersion=0.10.5 ¥ -DgroupId=io.helidon.examples ¥ -DartifactId=quickstart-se ¥ -Dpackage=io.helidon.examples.quickstart.se Helidon MP mvn archetype:generate -DinteractiveMode=false ¥ -DarchetypeGroupId=io.helidon.archetypes ¥ -DarchetypeArtifactId=helidon-quickstart-mp ¥ -DarchetypeVersion=0.10.5 ¥ -DgroupId=io.helidon.examples ¥ -DartifactId=quickstart-mp ¥ -Dpackage=io.helidon.examples.quickstart.mp
  14. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    18  mvn package java -jar target/quickstart-se.jar
  15. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Dockerfile #FROM openjdk:8-jre-slim FROM openjdk:8-jre-alpine RUN mkdir /app COPY libs /app/libs COPY quickstart-se.jar /app CMD ["java", "-jar", "/app/quickstart-se.jar"] 19
  16. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    20 Docker     docker build -t quickstart-se target docker run --rm -p 8080:8080 quickstart-se
  17. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    kind: Service apiVersion: v1 metadata: name: quickstart-se labels: app: quickstart-se spec: type: NodePort selector: app: quickstart-se ports: - port: 8080 targetPort: 8080 name: http --- kind: Deployment apiVersion: extensions/v1beta1 metadata: name: quickstart-se spec: replicas: 1 template: metadata: labels: app: quickstart-se version: v1 spec: containers: - name: quickstart-se image: quickstart-se:12alpine-custom imagePullPolicy: IfNotPresent ports: - containerPort: 8080 --- 21 app.yaml
  18. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    22 Kubernetes   kubectl create -f target/app.yaml kubectl get service
  19. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    24 Module $ jar --file=target/libs/helidon-common-0.10.5.jar --describe-module io.helidon.common jar:file:///Users/oracle/Documents/Helidon/quickstart- se8/target/libs/helidon-common-0.10.5.jar/!module-info.class exports io.helidon.common requires java.base mandated requires java.logging
  20. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Server (SE) # application.yaml app: greeting: "Hello" server: sockets: - secure: port: 443 backlog: 1024 receive-buffer: 0 timeout: 60000 ssl: .... - another: port: 12041 25 ServerConfiguration serverConfig = ServerConfiguration.fromConfig(config.get("server"));
  21. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    # 3 default MicroProfile Config sources: # System.getProperties() # System.getenv() # META-INF/microprofile-config.properties # default is localhost server.host=some.host # default is 7001 server.port=7011 # Helidon configuration (optional) # Length of queue for incoming connections. server.backlog: 512 # TCP receive window (Default:0) server.receive-buffer: 256 # Socket timeout (msec) defaults:0 (infinite) server.timeout: 30000 # Default is CPU_COUNT * 2 server.workers=4 # Default is not to use SSL ssl: private-key: keystore-resource-path: "certificate.p12" keystore-passphrase: "abcd" 26 Server (MP)
  22. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Routing (SE) 27 MPJAX-RS 2.0 private static Routing createRouting() { return Routing.builder() .register(JsonSupport.get()) .register("/greet", new GreetService()) .build(); } public class GreetService implements Service { ... public final void update(final Routing.Rules rules) { rules .get("/", this::getDefaultMessage) .get("/{name}", this::getMessage) .put("/greeting/{greeting}", this::updateGreeting); } }
  23. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    JSON 28 SEJSON-P private static Routing createRouting() { return Routing.builder() .register(JsonSupport.get()) .register("/greet", new GreetService()) .build(); } public class GreetService implements Service { ... public final void update(final Routing.Rules rules) { rules .get("/", this::getDefaultMessage) .get("/{name}", this::getMessage) .put("/greeting/{greeting}", this::updateGreeting); } }
  24. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Metrics • Prometheus  • maven    29 <dependencies> <dependency> <groupId>io.helidon.microprofile.metrics</groupId> <artifactId>helidon-metrics-se</artifactId> </dependency> </dependencies>
  25. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    30 import io.helidon.metrics.MetricsSupport; ... final MetricsSupport metrics = MetricsSupport.create(); ... // Endpoint final MetricsSupport metrics = MetricsSupport.create(); greetService = new GreetService(); return Routing.builder() .register(JsonSupport.get()) .register(metrics) .register("/greet", greetService) .get("/alive", Main::alive) .get("/ready", Main::ready) .build(); ...
  26. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    31 import io.helidon.metrics.RegistryFactory; import org.eclipse.microprofile.metrics.Counter; import org.eclipse.microprofile.metrics.MetricRegistry; ... private final MetricRegistry registry = RegistryFactory.getRegistryFactory() .get() .getRegistry(MetricRegistry.Type.APPLICATION); ... // Counter private final Counter greetCounter = registry.counter("accessctr"); ... // Counter   greetCounter.inc(); ...
  27. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    OpenTracing • Reactive Web ServerOpenTracing Zipkin •   ZipkinTracing  •   33 <dependency> <groupId>io.helidon.webserver</groupId> <artifactId>helidon-webserver-zipkin</artifactId> </dependency>
  28. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    34 // OpenTracing Tracer ServerConfiguration.builder() .tracer(new ZipkinTracerBuilder.forService("Tracing   ") .zipkin("ZipkinURL") .build()) .build()
  29. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    35 Routing  Routing.builder() .register(webSecurity) .register(JsonSupport.get()) .register(MetricsSupport.create()) .get("/ready", (req, res) -> { res.status(Http.Status.OK_200); res.send("Ready!"); }) .register(StaticContentSupport.builder("/WEB", Main.class.getClassLoader()) .welcomeFileName("index.html") .build()) .register("/greet", new GreetService()) .build(); <src>/resources  
  30. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

     •  •  •  • Audit 36   
  31. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Authentication   artifactId JWT Provider helidon-security-provider-jwt HTTP Basic Authorization helidon-security-provider-http-auth HTTP Digest Authorization helidon-security-provider-http-auth Header Assertion helidon-security-provider-header-atn HTTP Signatures helidon-security-provider-http-signature ABAC (Attribute based access control) Authorization helidon-security-provider-abac Google Login Authentication Provider helidon-security-provider-google-login OIDC (Open ID Connect) Authentication provider helidon-security-provider-oidc IDCS Role Mapping Provider helidon-security-provider-idcs-mapper 37    
  32. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    38 •   • Reactive Web Server  • Jersey  <dependency> <groupId>io.helidon.security</groupId> <artifactId>helidon-security</artifactId> </dependency> <dependency> <groupId>io.helidon.security</groupId> <artifactId>helidon-security-integration-webserver</artifactId> </dependency> <dependency> <groupId>io.helidon.security</groupId> <artifactId>helidon-security-integration-jersey</artifactId> </dependency>
  33. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

     •      39 private static WebSecurity createWebSecurity(final Config config) { Security security = Security.builder() .addProvider(GoogleTokenProvider .builder() .clientId( config.get("security.properties.google-client-id") .asString())) .build(); return WebSecurity.from(security); }
  34. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

     (2) • Routing   •     40 Routing.builder().register(webSecurity) .register(JsonSupport.get()) .register(MetricsSupport.create()) .register("/greet", new GreetService()) .build(); final Routing.Rules rules; rules.any(this::counterFilter) .get("/", this::getDefaultMessageHandler) .get("/greeting",this::getGreetingHandler) .get("/{name}", this::getMessageHandler) .put("/greeting/{greeting}", WebSecurity.authenticate(), this::updateGreetingHandler);
  35. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Etcd •   •  41 Etcd   <dependency> <groupId>io.helidon.config</groupId> <artifactId>helidon-config-etcd</artifactId> </dependency> Config config = Config.from( EtcdConfigSourceBuilder.from(URI.create("http://my-etcd:2379"), "/config.yaml", EtcdConfigSourceBuilder.EtcdApi.v3));
  36. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    43 Java 8, 11, 12... $ docker images quickstart-se REPOSITORY TAG IMAGE ID CREATED SIZE quickstart-se 12-oracle 35675acf14d4 7 days ago 468MB quickstart-se 11-oracle c3d347de8d23 7 days ago 469MB quickstart-se 8-alpine fae858de0489 7 days ago 88.6MB quickstart-se 8-slim 3a505f8068dc 7 days ago 210MB
  37. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    44 Java 8, 11, 12... $ docker images quickstart-se REPOSITORY TAG IMAGE ID CREATED SIZE quickstart-se 12-oracle 35675acf14d4 7 days ago 468MB quickstart-se 11-oracle c3d347de8d23 7 days ago 469MB quickstart-se 8-alpine fae858de0489 7 days ago 88.6MB quickstart-se 8-slim 3a505f8068dc 7 days ago 210MB    
  38. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    JRE • jdeps   • jlink   JRE 45 $ jdeps --list-deps quickstart-se.jar $ jlink --compress=2 --module-path /opt/openjdk-12/jmods ¥ --add-modules ¥ java.base,java.logging,java.sql,java.desktop ¥ --no-header-files ¥ --no-man-pages ¥ --output /linked
  39. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    46 FROM openjdk:11.0.1-jdk-oraclelinux7 AS jlink-package RUN jlink --compress=2 --module-path /usr/java/openjdk-11/jmods ¥ --add-modules java.base,java.logging,java.sql,java.desktop ¥ --no-header-files ¥ --strip-debug ¥ --no-man-pages ¥ --output /linked FROM oraclelinux:7-slim COPY --from=jlink-package /linked /usr/java/openjdk-11 ENV JAVA_HOME= /usr/java/openjdk-11 ENV PATH="$PATH:$JAVA_HOME/bin" RUN mkdir /app COPY libs /app/libs COPY quickstart-se.jar /app CMD ["java", "-jar", "/app/quickstart-se.jar"]    
  40. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    47 1/3  $ docker images quickstart-se REPOSITORY TAG IMAGE ID CREATED SIZE quickstart-se 12-oracle-custom edafa9a43204 7 days ago 172MB quickstart-se 12-oracle 35675acf14d4 7 days ago 468MB quickstart-se 11-oracle-custom acc0127977c8 7 days ago 172MB quickstart-se 11-oracle c3d347de8d23 7 days ago 469MB quickstart-se 8-alpine fae858de0489 7 days ago 88.6MB quickstart-se 8-slim 3a505f8068dc 7 days ago 210MB
  41. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    48 1/3  $ docker images quickstart-se REPOSITORY TAG IMAGE ID CREATED SIZE quickstart-se 12-oracle-custom edafa9a43204 7 days ago 172MB quickstart-se 12-oracle 35675acf14d4 7 days ago 468MB quickstart-se 11-oracle-custom acc0127977c8 7 days ago 172MB quickstart-se 11-oracle c3d347de8d23 7 days ago 469MB quickstart-se 8-alpine fae858de0489 7 days ago 88.6MB quickstart-se 8-slim 3a505f8068dc 7 days ago 210MB   
  42. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    • JDKAlpine Linux • Musl libc 49 Project Portola https://www.musl-libc.org/
  43. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    50 Alpine Linux... $ docker images quickstart-se REPOSITORY TAG IMAGE ID CREATED SIZE quickstart-se 12-alpine-custom d948b732d796 7 days ago 58.4MB quickstart-se 12-alpine ba31e688dcb6 7 days ago 341MB quickstart-se 12-oracle-custom edafa9a43204 7 days ago 172MB quickstart-se 12-oracle 35675acf14d4 7 days ago 468MB quickstart-se 11-oracle-custom acc0127977c8 7 days ago 172MB quickstart-se 11-oracle c3d347de8d23 7 days ago 469MB quickstart-se 8-alpine fae858de0489 7 days ago 88.6MB quickstart-se 8-slim 3a505f8068dc 7 days ago 210MB
  44. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Resources 52 https://github.com/oracle/helidon @helidon_project https://helidon.slack.com https://helidon.io
  45. Copyright © 2018, Oracle and/or its affiliates. All rights reserved.

    Safe Harbor Statement The preceding 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. 53