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

Spring Data, Hypermedia and the Cloud (JavaDay2016)

Spring Data, Hypermedia and the Cloud (JavaDay2016)

ALPS, HAL, HATEOAS, JSON Schema, Cloud, Docker,… are those just buzzwords? No! With Spring Data we allow you to expose your repositories as a REST resource including ALPS metadata, JSON Schema and simply everything you would probably expect. Join Christoph Strobl on his journey through the Spring stack while creating and deploying Hypermedia APIs as Docker containers, on Cloud Foundry and PCFDev.

B0e9230af37f3a883c88d3f11c00e174?s=128

Christoph Strobl

October 14, 2016
Tweet

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 1 Spring Data, Hypermedia and the Cloud Christoph Strobl @stroblchristoph JAVADAY KYIV 2016
  2. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 2
  3. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 “Spring Data provides a familiar and consistent Spring based programming model retaining store specific features and capabilities. O.Gierke
  4. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data Modules 4 Commons Neo4j Gemfire JPA Solr Elasticsearch REST Cassandra Couchbase Redis MongoDB Community
 modules Core
 modules Aerospike Hazelcast Crate KeyValue
  5. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 Today we’ll have a look at… Spring Boot App
  6. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 6 “Spring Boot makes it easy to create Spring-powered, production-grade applications and services with absolute minimum fuss. The Spring Boot Team
  7. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ One Slide App @SpringBootApplication public class StoreApp { ! public static void main(String[] args) { SpringApplication.run(StoreApp.class, args); } ! ! ! ! ! } 7 Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable); interface StoreRepository extends PagingAndSortingRepository<Store, String> { ! ! }
  8. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ § Hypermedia 8 Hypermedia is Coming image source:
 terrordesigners.com
  9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 9 Hypermedia? Spring MVC + JSON? Well, no. But HTTP and JSON then… Sorry,… but no. Got it HTTP and XML! No! image source:
 piratanegro.files.wordpress.com
  10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Hypermedia Presentation of data and navigation controls at the same time 10
  11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 11 HATEOAS JSON HAL JSON Schema GET PUT POST PATCH Conditional ALPS Repositories Projections Resource http
  12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HATEOAS 12 Hypermedia as the Engine of Application State Media Types describe resources. Actions are executed by following links. Response reflects state. Clients explore the API.
  13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ HAL 13 Hypertext Application Language Resource Links Embedded Resource State Name Target
  14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ALPS 14 Application Level Profile Semantics Closes the gap ! between state and transition. Descriptors semantic data safe GET unsafe POST idempotent PUT/DELTE
  15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ JSON Schema 15 Describes your JSON data format
  16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Data REST 16 @SpringBootApplication public class StoreApp { ! public static void main(String[] args) { SpringApplication.run(StoreApp.class, args); } ! interface StoreRepository extends PagingAndSortingRepository<Store, String> { ! ! } } Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable); @RestResource(rel = "by-location") <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId>
  17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17 Repository Resource Relation Link IDs URIs @Version ETags @LastModified Date Last-Modified What it does
  18. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Let’s try this local… 18 $> mvn spring-boot:run <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> [INFO] --- spring-boot-maven-plugin:run (default-cli) @ spring-data-rest-starbucks ---! _ ___ _ __ _! _ | |__ ___ ____ _| \ __ _ _ _ | |/ / _(_)_ __! | || / _` \ V / _` | |) / _` | || | | ' < || | \ V /! \__/\__,_|\_/\__,_|___/\__,_|\_, | |_|\_\_, |_|\_/! |__/ |__/! ! ...:: Spring Boot :: Microservices :: Cloud :: Spring Data REST ::...! ----------------! Kyiv, Oct. 14 - 15! ! ! 2016-09-21 10:16:44.416 INFO 38982 --- [StoreApp.main()] example.springdata.rest.stores.StoreApp : Starting StoreApp on christophs- mbp.home with PID 38982 (/Users/cstrobl/git/spring-data-examples/rest/starbucks/target/classes started by cstrobl in /Users/cstrobl/
  19. None
  20. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20 image source:
 terrordesigners.com The Cloud 
 is waiting! image source: idigitaltimes.com
  21. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 21 “Docker is an open platform for building, shipping and running distributed applications. It gives programmers, development teams and operations engineers the common toolbox they need to take advantage of the distributed and networked nature of modern applications.
 ! docker.com
  22. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Run on Docker 22 FROM java:8 VOLUME /tmp ADD spring-data-rest-starbucks.jar app.jar RUN bash -c 'touch /app.jar' ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar", "/app.jar"] <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.2.12</version> <configuration> <imageName>cstrobl/${project.artifactId}</imageName> 
 <dockerDirectory>src/main/docker<dockerDirectory>
 ... $> mvn package docker:build $> docker run -p 8080:8080 -t cstrobl/spring-data-rest-starbucks
  23. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 23 cstrobl> docker run -p 8080:8080 cstrobl/spring-data-rest-starbucks! _ ___ _ __ _! _ | |__ ___ ____ _| \ __ _ _ _ | |/ / _(_)_ __! | || / _` \ V / _` | |) / _` | || | | ' < || | \ V /! \__/\__,_|\_/\__,_|___/\__,_|\_, | |_|\_\_, |_|\_/! |__/ |__/! ! ...:: Spring Boot :: Microservices :: Cloud :: Spring Data REST ::...! ----------------! Kyiv, Oct. 14 - 15! ! ! 2016-09-21 08:25:03.540 INFO 1 --- [main] example.springdata.rest.stores.StoreApp : Starting StoreApp v1.0.0.BUILD-SNAPSHOT on 552fd85ba65f with PID 1 (/app.jar started by root in /)! 2016-09-21 08:25:03.599 INFO 1 --- [main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7280aa9a: startup date [Wed Sep 21 08:25:03 UTC 2016]; root of context hierarchy! 2016-09-21 08:25:10.340 INFO 1 --- [main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup! 2016-09-21 08:25:10.349 INFO 1 --- [main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0! 2016-09-21 08:25:10.523 INFO 1 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)! 2016-09-21 08:25:10.529 INFO 1 --- [main] example.springdata.rest.stores.StoreApp : Started StoreApp in 7.271 seconds (JVM running for 7.851)! ! ! ! cstrobl> docker ps! CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS ! 552fd85ba65f cstrobl/spring-data-rest-starbucks "java -Djava.securit 8 minutes ago Up 8 minutes 0.0.0.0:8080->8080/tcp ! 40d834572d45 mongo "/entrypoint.sh mong 18 minutes ago Up 18 minutes 0.0.0.0:27017->27017/tcp ! ! ! !
  24. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 24 “PCF Dev gives application developers the full Cloud Foundry experience in a lightweight, easy to install package designed to run on a developer’s laptop or workstation. ! pivotal-cf/pcfdev
  25. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 25 Cloud Foundry at a glance
  26. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 26 …that’s huge 
 and a bit scary
  27. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Get PCF Dev 27 $> http --follow —download …/pcfdev/pcfdev-VERSION-PLATFORM.zip $> ./pcfdev-VERSION $> cf dev start Just as simple as that !
  28. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 28 cstrobl> $ cf dev start! Please retrieve your Pivotal Network API from:! https://network.pivotal.io/users/dashboard/edit-profile! ! API token> ********! ! Downloading VM...! Progress: |====================>| 100%! VM downloaded.! ! Allocating 4096 MB out of 16384 MB total system memory (6279 MB free).! ! Importing VM...! Starting VM...! Provisioning VM...! Waiting for services to start...! 50 out of 50 running! _______ _______ _______ ______ _______ __ __! | || || | | | | || | | |! | _ || || ___| | _ || ___|| |_| |! | |_| || || |___ | | | || |___ | |! | ___|| _|| ___| | |_| || ___|| |! | | | |_ | | | || |___ | |! |___| |_______||___| |______| |_______| |___|! is now running.! ! To begin using PCF Dev, please run:! cf login -a https://api.local.pcfdev.io --skip-ssl-validation! Admin user => Email: admin / Password: admin! Regular user => Email: user / Password: pass cstrobl> $ cf login -a https://api.local.pcfdev.io —skip-ssl-valid! API endpoint: https://api.local.pcfdev.io! ! Email> admin! Password> *****! Authenticating...! OK! ! API endpoint: https://api.local.pcfdev.io (API version: 2.54.0)! User: admin! Org: pcfdev-org! Space: pcfdev-space! ! ! ! ! !
  29. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Run on PCF Dev 29 $> mvn package $> cf push starbucks -p target/spring-data-rest-starbucks.jar + Run it - I do not care how ! $> cf scale starbucks -i 2
  30. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 30 cstrobl> cf push starbucks -p target/spring-data-rest-starbucks.jar! Creating app starbucks in org pcfdev-org / space pcfdev-space as admin...! OK! ! Uploading starbucks...! Uploading 28.7M, 174 files! Done uploading! OK! ! Starting app starbucks in org pcfdev-org / space pcfdev-space as admin…! 1 of 1 instances running! App started! ! requested state: started! instances: 1/1! usage: 256M x 1 instances! urls: starbucks.local.pcfdev.io! last uploaded: Wed Sep 21 08:42:19 UTC 2016! stack: cflinuxfs2! buildpack: java-buildpack=v3.6-offline-https://github.com/cloudfoundry/java-buildpack.git#5194155 java-main open-jdk-like-jre=1.8.0_71 open-jdk-like-memory-calculator=2.0.1_RELEASE spring-auto- reconfiguration=1.10.0_RELEASE! ! state since cpu memory disk details! #0 running 2016-09-21 10:43:38 AM 0.0% 0 of 256M 0 of 512M!
  31. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 31 “Pivotal Cloud Foundry is a Platform as a Service that supplies developers with a ready-to-use cloud computing environment and application services, all hosted by virtualized servers on your existing public and private infrastructure. ! pivotal.io
  32. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Run on Pivotal Cloud Foundry 32 $> mvn package $> cf push starbucks -p target/spring-data-rest-starbucks.jar --no-start $> cf bind-service starbucks mongo $> cf start starbucks
 $> cf scale starbucks -i 2 -m 512M
  33. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 33
  34. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 34 Go to start.spring.io 
 get Spring Boot with Spring Data 
 and deploy on
 Cloud Foundry, Docker, PCFDev, Lattice
 or simply anywhere you want!
  35. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Resources (alphabetical) § alps.io/spec/ § docker.com § hub.docker.com § json-schema.org § lattice.cf § mongodb.org § pivotal-cf/pcf-dev 35 § projects.spring.io/spring-boot § projects.spring.io/spring-data § run.pivotal.io § start.spring.io § stateless.co/hal_specification § vagrantup.com § virtualbox.org