UiPath Platform: The Backend Engine Powering Your Automation - Session 1
Why PCF is the best platform for Spring Boot
1. 1
Why PCF is the best platform for
Spring Boot
2017-07-20
Toshiaki Maki (@making)
2. Who am I ?
2
Toshiaki Maki (@making) https://blog.ik.am
Sr. Solutions Architect @Pivotal Japan
Spring Framework 💖
Cloud Foundry 💖
3. Platform Spring Specific Comparison
3
AWS
BeanStalk
Azure
WebApps
Google
AppEngine
Heroku OpenShift
/k8s
PCF/
PWS
Spring
Cloud
Connector
Spring Cloud
Connector
Heroku
Spring Cloud
Connector Cloud
Foundry
Spring Boot
Integration
* cloud profile
* Apps Manager
Spring Boot
Actuator Support
* Metric
Forwarder
Spring
Cloud
Integration
Spring
Cloud AWS
Spring Cloud
GCP
* Spring
Cloud
Kubernetes
* SCDF
* Spring Cloud
Services
* Trace Exporter
* SCDF
4. Platform Spring Specific Comparison
3
AWS
BeanStalk
Azure
WebApps
Google
AppEngine
Heroku OpenShift
/k8s
PCF/
PWS
Spring
Cloud
Connector
Spring Cloud
Connector
Heroku
Spring Cloud
Connector Cloud
Foundry
Spring Boot
Integration
* cloud profile
* Apps Manager
Spring Boot
Actuator Support
* Metric
Forwarder
Spring
Cloud
Integration
Spring
Cloud AWS
Spring Cloud
GCP
* Spring
Cloud
Kubernetes
* SCDF
* Spring Cloud
Services
* Trace Exporter
* SCDF
6. Why PCF for Spring?
4
Because Pivotal Cloud Foundry gives us
a lot of out-of-the-box features
to manage / operate Spring Boot apps
7. Why PCF for Spring?
4
Because Pivotal Cloud Foundry gives us
a lot of out-of-the-box features
to manage / operate Spring Boot apps
8. Why PCF for Spring?
4
Because Pivotal Cloud Foundry gives us
a lot of out-of-the-box features
to manage / operate Spring Boot apps
12 Factors Apps
Microservices
Security
Tracing
Metrics
9. Spring Support in PCF
5
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service
10. Spring Support in PCF
6
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service
11. "profile" in Spring
7
without PCF/PWS
myapp.foo=I am in local env.
message=I am a default property.
logging.level.com.example=DEBUG
myapp.foo=I am in AWS.
message=I am a production property
logging.level.com.example=INFO
application.properties
application-prod.properties
java -jar app.jar --spring.profiles.active=prod
12. cloud profile
8
with PCF/PWS
myapp.foo=I am in local env.
message=I am a default property.
logging.level.com.example=DEBUG
myapp.foo=I am in cloud foundry.
message=I am a cloud property.
logging.level.com.example=INFO
application.properties
application-cloud.properties
java -jar app.jar --spring.profiles.active=cloud
13. cloud profile
8
with PCF/PWS
myapp.foo=I am in local env.
message=I am a default property.
logging.level.com.example=DEBUG
myapp.foo=I am in cloud foundry.
message=I am a cloud property.
logging.level.com.example=INFO
application.properties
application-cloud.properties
java -jar app.jar --spring.profiles.active=cloud
cloud profile is set
by java-buildpack
14. Spring Support in PCF
9
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service
22. ⚠ Do NOT use default datasource
15
with PCF/PWS
https://discuss.pivotal.io/hc/en-us/articles/221898227-Connection-pool-warning-message-maxIdle-is-larger-than-
maxActive-setting-maxIdle-to-4-seen-in-PCF-deployed-Spring-app
org.apache.tomcat.jdbc.pool.ConnectionPool WARNING
maxIdle is larger than maxActive, setting maxIdle to: 4
23. ⚠ Do NOT use default datasource
15
with PCF/PWS
https://discuss.pivotal.io/hc/en-us/articles/221898227-Connection-pool-warning-message-maxIdle-is-larger-than-
maxActive-setting-maxIdle-to-4-seen-in-PCF-deployed-Spring-app
org.apache.tomcat.jdbc.pool.ConnectionPool WARNING
maxIdle is larger than maxActive, setting maxIdle to: 4
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [...]
Timeout: Pool empty. Unable to fetch a connection in 30
seconds, none available[size:4; busy:4; idle:0; lastwait:30000]
😱
24. ⚠ Do NOT use default datasource
16
with PCF/PWS
@Profile("cloud")
public class CloudConfig extends AbstractCloudConfig {
@Bean
public DataSource dataSource() {
PooledServiceConnectorConfig.PoolConfig poolConfig
= new PooledServiceConnectorConfig.PoolConfig(
5 /* min */, 30 /* max */, 3000 /* wait */);
return connectionFactory()
.dataSource(new DataSourceConfig(poolConfig, null));
}
}
25. Spring Support in PCF
17
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service
26. Microservices with Spring Cloud
18
without PCF/PWS
Spring Boot
App
Spring Boot
App
Service Registry
(Eureka)
Config Server
Circuit Breaker Dashboard
(Hystrix Dashboard)
You manage
(deploy + security)
You manage
(deploy + security)
You manage
(deploy + security)
27. Spring Cloud Services
19
with PCF/PWS
Spring Boot
App
Spring Boot
App
Service Registry
(Eureka)
Config Server
Circuit Breaker Dashboard
(Hystrix Dashboard)
PCF manage
(cf cs & cf bs)
PCF manage
(cf cs & cf bs)
PCF manage
(cf cs & cf bs)
19
UAA
28. Spring Support in PCF
20
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service
29. Distributed Tracing with Zipkin
21
Spring Boot
App
Spring Boot
App
Spring Boot
App
without PCF/PWS
Spring Boot
App
Zipkin
You manage
(deploy + security)
X-B3-SpaceId
X-B3-TraceId
34. Spring Support in PCF
26
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service
45. Secure with Spring Security
33
without PCF/PWS
@EnableWebSecurity
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class ActuatorSecurityConfig
extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/admin/**").authorizedRequests()
.anyRequest().hasRole("ACTUATOR")
.and().httpBasic()
.and().csrf().disable();
}
// ...
}
management.context-path=/admin
46. Spring Actuator Support
in Apps Manager
34
Spring Boot
Actuator
/cloudfoundryapplication/health,
/cloudfoundryapplication/info, ...
Apps Manager
UAA
token
token
with PCF/PWS
Cloud
Controller
token
permission
47. Spring Actuator Support in Apps Manager
5
Endpoint Description Supported Version
/dump Get thread dump 🆕 1.11~
/env Get env variables, properties
/metrics Get application's metrics
/health Get the result of health checks ✅ 1.9~
/info Get build information ✅ 1.9~
/loggers Change logging level ✅ 1.9~
/trace Get request trace log 🆕 1.11~
/heapdump Download heap dump 🆕 1.11~
59. Spring Support in PCF
47
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service
60. Spring Actuator Support in Apps Manager
8
Endpoint Description Supported Version
/dump Get thread dump 🆕 1.11~
/env Get env variables, properties
/metrics Get application's metrics
/health Get the result of health checks ✅ 1.9~
/info Get build information ✅ 1.9~
/loggers Change logging level ✅ 1.9~
/trace Get request trace log 🆕 1.11~
/heapdump Download heap dump 🆕 1.11~
61. Spring Actuator Support in Apps Manager
8
Endpoint Description Supported Version
/dump Get thread dump 🆕 1.11~
/env Get env variables, properties
/metrics Get application's metrics
/health Get the result of health checks ✅ 1.9~
/info Get build information ✅ 1.9~
/loggers Change logging level ✅ 1.9~
/trace Get request trace log 🆕 1.11~
/heapdump Download heap dump 🆕 1.11~
70. Metrics Forwarder Service
51
comes with java buildpack v3.18/4.2+
Enables Actuator's MetricsWriter to Metrics
Forwarder Service automatically
https://github.com/cloudfoundry/java-buildpack-metric-writer
https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-metric_writer.md
with PCF/PWS
71. Metrics Forwarder Service
52
Spring Boot
Actuator
Metrics Writer
Java
buildpack
Metrics
Forwarder
Service
bind
TSDB
Dashboard
send
send
with PCF/PWS
72. Metrics Forwarder Service
53
cf bind-service myapp mf
cf cups mf -p '{"endpoint":"X","access_token":"X"}'
cf create-service metric-forwarder plan mf
OR
THEN
with PCF/PWS
73. DEMO Scenario
54
Spring Boot
Actuator
Metrics Writer
Java
buildpack
Metrics
Forwarder
Service
bind
Grafana
Prometheus
scrape
send
works as
* Metrics Forwarder Service
* Service Broker
* Prometheus Exporter
PromQL
76. Integration with PCF (Future)
57
Spring Boot
Actuator
Metrics Writer
Java
buildpack
Metrics
Forwarder
Service
bind
PCF Metrics,
Autoscaler
send
send
will be provided as a "tile"
77. Recap
58
Why PCF is best platform for Spring
➡ a lot of out-of-the-box features
• cloud profile
• Spring Cloud Connectors
• Spring Cloud Services
• Trace Exporter
• Spring Actuator Support in Apps Manager
• Metrics Forwarder Service