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

Spring Data, Hypermedia and the Cloud by Christoph Strobl

Riga Dev Day
March 13, 2016
46

Spring Data, Hypermedia and the Cloud by Christoph Strobl

Riga Dev Day

March 13, 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/ Spring Data, Hypermedia and the Cloud Christoph Strobl, Pivotal Software Inc. @stroblchristoph
  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 Incubating 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>
  19. 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
  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/ 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
  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/ 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
  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/ 23
  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/ 24 “Lattice aspires to make clustering containers easy. It packages components from Cloud Foundry to provide a cloud native platform for individual developers and small teams.
 ! lattice.cf
  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/ Run on Lattice 25 $> mvn package docker:build $> docker push cstrobl/spring-data-rest-starbucks $> ltc create starbucks cstrobl/spring-data-rest-starbucks --memory-mb=0
 $> ltc scale starbucks 2
  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/ 26
  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/ 27 “MicroPCF 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/micropcf
  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/ 28 Cloud Foundry at a glance
  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/ 29 …that’s huge 
 and a bit scary
  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/ Get MicroPCF 30 $> http --follow —download …/micropcf/releases/download/v0.5.0/Vagrantfile-... $> vagrant up Just as simple as that !
  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/ 31
  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/ Run on MicroPCF 32 $> mvn package $> cf push starbucks -p target/spring-data-rest-starbucks.jar + Run it - I do not care how ! $> cf scale starbucks -i 2
  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/ 33
  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/ 34 “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
  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/ Run on Pivotal Cloud Foundry 35 $> 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
  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/ 36
  36. 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/ 37 Go to start.spring.io 
 get Spring Boot with Spring Data 
 and deploy on
 Cloud Foundry, Docker, MicroPCF, Lattice
 or simply anywhere you want!
  37. 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/micropcf 38 § projects.spring.io/spring-boot § projects.spring.io/spring-data § run.pivotal.io § start.spring.io § stateless.co/hal_specification § vagrantup.com § virtualbox.org