Save 37% off PRO during our Black Friday Sale! »

Abstracting PaaS services to be portable with Spring Cloud

Abstracting PaaS services to be portable with Spring Cloud

Developing an application to a cloud platform involves working with a deployed application's environment and connecting to services. Spring Cloud, a new project, simplifies these tasks in a variety of cloud platforms including Cloud Foundry and Heroku. Spring Cloud makes it possible to deploy the same artifact (a war or a jar) to multiple cloud environments. It supports multiple clouds through the concept of Cloud Connector and provides out of the box implementation for Cloud Foundry and Heroku, and extension points for other cloud platforms. In this talk, we will introduce the Spring Cloud project, show how you can simplify configuring applications for cloud deployment, discuss its extensibility mechanism, and put it to good use by showing practical examples from the field.

8c4fc02a9c43859ebdece12b66d5ad6b?s=128

Ramnivas Laddad

June 03, 2014
Tweet

Transcript

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

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Abstracting PaaS services to be portable with Spring Cloud Ramnivas Laddad, Pivotal Software, Inc. @ramnivas Tuesday, June 3,
  2. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 2 Agenda § Spring Cloud Basics § Application Config Options • Java config • XML config § Extensibility mechanism • Cloud Platforms • Cloud Services • Frameworks Tuesday, June 3,
  3. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness 3 Tuesday, June 3,
  4. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness 3 Application Tuesday, June 3,
  5. Container Unless otherwise indicated, these slides are © 2013-2014 Pivotal

    Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness 3 Application Tuesday, June 3,
  6. Container Unless otherwise indicated, these slides are © 2013-2014 Pivotal

    Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness 3 Application App Instance Information Tuesday, June 3,
  7. Container Unless otherwise indicated, these slides are © 2013-2014 Pivotal

    Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness 3 Application Service App Instance Information Tuesday, June 3,
  8. Container Unless otherwise indicated, these slides are © 2013-2014 Pivotal

    Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness 3 Application Service Services Information App Instance Information Tuesday, June 3,
  9. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness: Cloud Foundry Services § VCAP_SERVICES env variable { "elephantsql": [ { "name" : "inventory-db", "label" : "elephantsql", "tags" : ["relational","Data Store","postgresql"], "plan" : "turtle", "credentials" : { "uri" : "postgres://user:pass@babar.elephantsql.com:5432/db", "max_conns" : "5" } } ], "rediscloud": [ { "name" : "rediscloud-service", "label" : "rediscloud", "tags" : ["key-value","redis","Data Store"], "plan" : "25mb", "credentials" : { "hostname" : "pub-redis.garantiadata.com", "port" : "11853", "password" : "pass" } } ] } 4 Tuesday, June 3,
  10. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness: Cloud Foundry Instance Information § VCAP_APPLICATION env variable { "limits": { "mem" : 512, "disk" : 1024, "fds" : 16384 }, "application_version":"5e6fe3f7-6900-4af8-8376-bf3223ce886b", "application_name":"hello-spring-cloud", "application_uris":["myapp.cfapps.io"], "version":"5e6fe3f7-6900-4af8-8376-bf3223ce886b", "name":"hello-spring-cloud", "space_name":"development", "space_id":"5f629937-1821-4f48-9eb4-8c67c70c0df0", "instance_id":"b84fa4cd1c75431486dec1609828ae36", "instance_index":0, "host":"0.0.0.0", "port":63202, "started_at_timestamp":1401394307, "state_timestamp":1401394307 } 5 Tuesday, June 3,
  11. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness: Heroku Services § One environment variable per service HEROKU_POSTGRESQL_PURPLE_URL postgres://user:pass@host.amazonaws.com:5432/db REDISCLOUD_URL redis://rediscloud:pass@host.garantiadata.com:19038 REDISTOGO_URL redis://redistogo:pass@host.redistogo.com:9139 6 Tuesday, June 3,
  12. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Apps Awareness: Heroku Instance Information § Individual env variables PORT 12345 DYNO web.1 7 Tuesday, June 3,
  13. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Cloud Goals § Abstraction over cloud services and application environment § Implementation for multiple cloud platforms • Cloud Foundry • Heroku § Extensibility without modifying the core code • Cloud Connector • Service Creator 8 Tuesday, June 3,
  14. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 9 Using Java Config Tuesday, June 3,
  15. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 10 Scanning for services @Configuration @ServiceScan public class CloudConfig { } Tuesday, June 3,
  16. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 10 Scanning for services @Configuration @ServiceScan public class CloudConfig { } Tuesday, June 3,
  17. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 11 Taking over control @Configuration public class CloudConfig extends AbstractCloudConfig { @Bean public DataSource dataSource() { return connectionFactory().dataSource(); } @Bean public MongoDbFactory mongoDb() { return connectionFactory().mongoDbFactory(); } } Tuesday, June 3,
  18. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 12 Taking over control: Working with specific services @Configuration public class CloudConfig extends AbstractCloudConfig { @Bean public DataSource inventoryDataSource() { return connectionFactory().dataSource("inventory-service"); } @Bean public DataSource customerDataSource() { return connectionFactory().dataSource("customers-service"); } } Tuesday, June 3,
  19. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 13 Taking over control: Configuring Services @Configuration public class CloudConfig extends AbstractCloudConfig { @Bean public DataSource inventoryDataSource() { PoolConfig poolConfig = new PoolConfig(20, 200); ConnectionConfig connectionConfig = new ConnectionConfig("characterEncoding=UTF-8"); DataSourceConfig serviceConfig = new DataSourceConfig(poolConfig, connectionConfig); return connectionFactory().dataSource( "inventory-service", serviceConfig); } } Tuesday, June 3,
  20. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 14 Acquiring generic services @Configuration public class CloudConfig extends AbstractCloudConfig { @Bean public Search search() { return connectionFactory().service( "search-service", Search.class); } } Tuesday, June 3,
  21. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 15 Using XML Config Tuesday, June 3,
  22. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 16 Scanning for services <cloud:service-scan/> Tuesday, June 3,
  23. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17 Taking over control <cloud:data-source> <cloud:mongo-db-factory/> ... Tuesday, June 3,
  24. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 18 Taking over control: Specifying services <cloud:data-source service-name="inventory-service"> <cloud: data-source service-name="customers-service"/> Tuesday, June 3,
  25. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 19 Taking over control: Configuring Services <cloud:data-source service-name="inventory-service"> <cloud:pool pool-size="20" max-wait-time="200"/> <cloud:connection properties="characterEncoding=UTF-8"/> </cloud:data-source> Tuesday, June 3,
  26. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20 Acquiring generic services <cloud:service service-name="search-service"/> Tuesday, June 3,
  27. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 20 Acquiring generic services <cloud:service service-name="search-service"/> <cloud:service service-name="search-service" connector-type="com.example.Search"/> Tuesday, June 3,
  28. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 21 Spring Cloud Extensibility Tuesday, June 3,
  29. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Axis of Extensibility 22 Tuesday, June 3,
  30. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Axis of Extensibility 22 Cloud Platform Tuesday, June 3,
  31. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Axis of Extensibility 22 Cloud Platform Cloud Services Tuesday, June 3,
  32. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Axis of Extensibility 22 Cloud Platform Cloud Services Framework Support Tuesday, June 3,
  33. Service Connector ServiceInfo Unless otherwise indicated, these slides are ©

    2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Extensibility Overview 23 CloudConnector ServiceConnectorCreator Service Connector Service Connector Tuesday, June 3,
  34. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Platform Extensibility 24 public interface CloudConnector { boolean isInMatchingCloud(); ApplicationInstanceInfo getApplicationInstanceInfo(); List<ServiceInfo> getServiceInfos(); } Tuesday, June 3,
  35. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Registering Cloud Connector 25 § Add a line with the class name to /META-INF/services/org.springframework.cloud.CloudConnector • Cloud Foundry example: org.springframework.cloud.cloudfoundry.CloudFoundryConnector • Heroku example: org.springframework.cloud.heroku.HerokuConnector Tuesday, June 3,
  36. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Service Extensibility 26 Tuesday, June 3,
  37. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Service Extensibility 26 public interface ServiceInfo { public String getId(); } Tuesday, June 3,
  38. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Cloud Service Extensibility 26 public interface ServiceInfoCreator<SI extends ServiceInfo, SD> { public boolean accept(SD serviceData); public SI createServiceInfo(SD serviceData); } public interface ServiceInfo { public String getId(); } Tuesday, June 3,
  39. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Registering Service Info Creators 27 § Each Cloud Connector can choose any scheme it prefers § For Cloud Foundry Cloud Connector /META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator Tuesday, June 3,
  40. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Registering Service Info Creators 27 § Each Cloud Connector can choose any scheme it prefers § For Cloud Foundry Cloud Connector /META-INF/services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator org.springframework.cloud.cloudfoundry.MysqlServiceInfoCreator org.springframework.cloud.cloudfoundry.PostgresqlServiceInfoCreator org.springframework.cloud.cloudfoundry.RedisServiceInfoCreator org.springframework.cloud.cloudfoundry.MongoServiceInfoCreator org.springframework.cloud.cloudfoundry.AmqpServiceInfoCreator org.springframework.cloud.cloudfoundry.MonitoringServiceInfoCreator org.springframework.cloud.cloudfoundry.SmtpServiceInfoCreator org.springframework.cloud.cloudfoundry.OracleServiceInfoCreator Tuesday, June 3,
  41. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Framework extensibility 28 § Mapping ServiceInfo to framework-specific service connector • ReltionalServiceInfo -> DataSource • MongoServiceInfo -> MongoDbFactory • ... public interface ServiceConnectorCreator<SC, SI extends ServiceInfo> { SC create(SI serviceInfo, ServiceConnectorConfig serviceConnectorConfig); Class<SC> getServiceConnectorType(); Class<?> getServiceInfoType(); } Tuesday, June 3,
  42. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Framework extensibility registration 29 § Each framework may choose any mechanism § Spring Extension • /META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator Tuesday, June 3,
  43. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Framework extensibility registration 29 § Each framework may choose any mechanism § Spring Extension • /META-INF/services/org.springframework.cloud.service.ServiceConnectorCreator org.springframework.cloud.service.relational.MysqlDataSourceCreator org.springframework.cloud.service.relational.PostgresqlDataSourceCreator org.springframework.cloud.service.relational.OracleDataSourceCreator org.springframework.cloud.service.keyval.RedisConnectionFactoryCreator org.springframework.cloud.service.document.MongoDbFactoryCreator org.springframework.cloud.service.messaging.RabbitConnectionFactoryCreator org.springframework.cloud.service.smtp.MailSenderCreator Tuesday, June 3,
  44. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s next § Deeper support for Spring Boot applications § Support for many more services • Elastic Search • Memcache • Riak • Cassandra • Neo4j • ... § Support for other cloud platforms § Support for other frameworks? 30 Tuesday, June 3,
  45. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s next § Deeper support for Spring Boot applications § Support for many more services • Elastic Search • Memcache • Riak • Cassandra • Neo4j • ... § Support for other cloud platforms § Support for other frameworks? 30 Community Contributions Welcome! Tuesday, June 3,
  46. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 31 Learn More. Stay Connected. § Try the sample apps and then use it in your own. • See http://projects.spring.io/spring- cloud § Tell us what you will like to see in Spring Cloud § Contribute support for new cloud connectors and services Twitter: twitter.com/springcentral YouTube: spring.io/video LinkedIn: spring.io/linkedin Google Plus: spring.io/gplus Tuesday, June 3,
  47. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Abstracting PaaS services to be portable with Spring Cloud Ramnivas Laddad, Pivotal Software, Inc. @ramnivas Tuesday, June 3,