Professional Documents
Culture Documents
Applications with
Cloud Foundry
Hands-On Workshop
Version 1.6.b
© Copyright2016
© Copyright 2014 Pivotal.
2015 Pivotal.All rights reserved.
All rights reserved 1
Copyright Notice
Copyright © 2015
2016 Pivotal Software, Inc. All rights reserved. This manual and its accompanying
materials are protected by U.S. and international copyright and intellectual property laws.
Pivotal products are covered by one or more patents listed at http://www.pivotal.io/patents.
Pivotal is a registered trademark or trademark of Pivotal Software, Inc. in the United States and/or
other jurisdictions. All other marks and names mentioned herein may be trademarks of their respective
companies. The training material is provided “as is,” and all express or implied conditions,
representations, and warranties, including any implied warranty of merchantability, fitness for a
particular purpose or non-infringement, are disclaimed, even if Pivotal Software, Inc., has been
advised of the possibility of such claims. This training material is designed to support an instructor-led
training course and is intended to be used for reference purposes in conjunction with the instructor-led
training course. The training material is not a standalone training tool. Use of the training material for
self-study without class attendance is not recommended.
These materials and the computer programs to which it relates are the property of, and embody trade
secrets and confidential information proprietary to, Pivotal Software, Inc., and may not be reproduced,
copied, disclosed, transferred, adapted or modified without the express written approval of Pivotal
Software, Inc.
© Copyright2016
© Copyright 2015 Pivotal.
Pivotal.All rights reserved.
All rights reserved -2- Version 1.6.b 1
Developing Applications
with Cloud Foundry
Introduction
Course Agenda and Pivotal Background
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved -3- Version 1.6.b 1
Logistics
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved -4- Version 1.6.b 2
How You will Benefit
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved -5- Version 1.6.b 3
Covered in this section
• Topics
• Lab Setup
• Pivotal
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved -6- Version 1.6.b 4
Day 1 – Pivotal CF Basics
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved -7- Version 1.6.b 5
Day 2 – Pivotal CF
• Using Services
• Using Buildpacks
• Managing Applications in Cloud Foundry
– 3rd Party Log Management, Monitoring, Autoscaling, Zero-
downtime deployments
• Cloud Foundry Architecture and Components
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved -8- Version 1.6.b 6
Day 3 – Management and Development
• Continuous Delivery
• Application Design Principles
• Spring for Cloud Applications
• Deploying Java and JVM Applications
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved -9- Version 1.6.b 7
Covered in this section
• Topics
• Lab Setup
• Pivotal
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 10 - Version 1.6.b 8
Lab Environment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 11 - Version 1.6.b 9
Pivotal CF Installation /
Pivotal Web Services Account
• Exercises will require a Pivotal CF environment
– Your organization may already have one
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 12 - Version 1.6.b 10
Cloud Foundry –
Command Line Interface (CLI)
• Most exercises involve running commands to interact
with Cloud Foundry
• Install Cloud Foundry Command Line Interface
– Visit https://console.run.pivotal.io/tools
• or https://github.com/cloudfoundry/cli
– Download / Run installer for your platform
• English, French, Mandarin, Portuguese, Spanish available
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 13 - Version 1.6.b 11
Eclipse / Spring Tool Suite
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 14 - Version 1.6.b 12
GitHub
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 15 - Version 1.6.b 13
Covered in this section
• Topics
• Lab Setup
• Pivotal
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 16 - Version 1.6.b 14
Pivotal
• A collaboration between
– EMC
– VMware
– General Electric
• Born on April 1, 2013
– Pre-IPO
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 17 - Version 1.6.b 15
Option 2
Pivotal Platform
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 18 - Version 1.6.b 16
Summary
• Agenda
• Pivotal
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 19 - Version 1.6.b 17
Lab
Setup Lab Environment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 20 - Version 1.6.b 18
What is Cloud
Foundry?
Overview
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 21 - Version 1.6.b 1
What is Cloud Foundry?
• Introduction to Cloud
• Cloud Foundry
• Key Concepts
• Pivotal CF
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 22 - Version 1.6.b 2
“The Cloud”
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 23 - Version 1.6.b 3
Types of Cloud Computing: IaaS
• Infrastructure as a Service
– Replacement for physical hardware
– Provides virtual hardware, OS, Network
– Amazon Web Services (AWS), RackSpace, Microsoft
Azure, VMware vCloud Air
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 24 - Version 1.6.b 4
Types of Cloud Computing: PaaS
• Platform as a Service
– More than a raw machine with OS
– Provides ready-made platform for running apps
– CloudFoundry, Heroku, Google App Engine, Amazon
Elastic Beanstalk
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 25 - Version 1.6.b 5
Types of Cloud Computing: SaaS
• Software as a Service
– Complete software application
– SalesForce.com, Google Apps, hundreds of examples
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 26 - Version 1.6.b 6
You Manage
Cloud Enablement
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 28 - Version 1.6.b 8
What is Cloud Foundry?
• Introduction to Cloud
• Cloud Foundry
• Key Concepts
• Pivotal CF
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 29 - Version 1.6.b 9
Cloud Foundry – The Open PaaS
Public Private
Clouds Clouds
CUSTOM CUSTOM
RUNTIMES SERVICES
Open
Source
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 30 - Version 1.6.b 10
Why Cloud Foundry?
• Open Source
– Reduce vendor-lock
• Public OR Private
• Language Independence
– Via Buildpacks
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 31 - Version 1.6.b 11
Cloud Foundry: Foundation
Open Governance
Platinum
Gold
Silver
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 32 - Version 1.6.b 12
An Explanation of the Various Web Sites
URL Details
cloudfoundry.org • The open source project's home page
• No hosting of any kind here.
• Documentation
github.com/cloudfoundry • The location of the source
• Download, build, and run if you like!
cloudfoundry.com • Old commercial web-site
• Superseded by run.pivotal.io
• Redirects to pivotal.io product page
blog.cloudfoundry.org • Technical blog
run.pivotal.io • Pivotal Web Services (PWS)
• Pivotal's hosted environment, runs PivotalCF
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 33 - Version 1.6.b 13
A Major Cloud Foundry Site
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 34 - Version 1.6.b 14
Cloud Foundry Architecture
High-Level View – more details later
Cloud Service
Service
Cloud Controller
Controller
Broker(s)
Broker(s)
EA
EA EA
EA EA
EA EA
EA
Router
Container
Container Container Container
Container
Container
Container Container
Container Container
Container
Container
Messaging
Messaging(NATS)
(NATS)
B O S H
EA = Execution Agent
= A VM where apps run
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 35 - Version 1.6.b 15
DEA vs DIEGO
• Execution Agents
– This course generically refers to Execution Agents
• Virtual Machines (VMs) where applications run
• Could be a DEA or a Diego Cell
– Almost all course content applies to either implementation
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 36 - Version 1.6.b 16
What is Cloud Foundry?
• Introduction to Cloud
• Cloud Foundry
• Key Concepts
• Pivotal CF
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 37 - Version 1.6.b 17
Cloud Foundry Platform as a Service
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 38 - Version 1.6.b 18
From VM Centric to Application Centric
App App App App
Configurations Configurations
Manifests, Automations
JVM JVM
App Server App Server
App Server App Server
VM VM
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 39 - Version 1.6.b 19
IaaS: VM-centric Deployment
}
Application
VM
Infrastructure
}
App Server (Tomcat)
VM
Infrastructure
Scaling = creating containers in a VM pool
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 42 - Version 1.6.b 22
What is Cloud Foundry?
• Introduction to Cloud
• Cloud Foundry
• Key Concepts
• Pivotal CF
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 43 - Version 1.6.b 23
Which Cloud Foundry Product?
PWS
● Open Source ● Pivotal Web Services ● Commercial product
● Setup and run a PaaS ● Public CF PaaS run/ ● Run private PaaS in-
for yourself managed by Pivotal house, or
● No paid support ● Hosted on AWS ● Create public PaaS
● No tools ● No guaranteed SLAs, (ISP managed)
not for production ● Sophisticated Web
● Support offered Console (App Mgr)
● Additional Tools (Ops
PWS-E Mgr)
● PWS Enterprise ● Less hassle
● For existing Pivotal ● Support offered
customers to use PWS
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 44 - Version 1.6.b 24
What is Pivotal CF?
www.pivotal.io/pivotal-products/pivotal-cf
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 45 - Version 1.6.b 25
Pivotal CF: Enterprise PaaS
Commercially Supported
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 46 - Version 1.6.b 26
OSS
Managed Services
Foundry Components
Mobile Services
App Manager
Messaging
Services
Services
+
Console
Elastic Core Cloud
Data
Pivotal
Runtime Support
B O S H
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 47 - Version 1.6.b 27
Pivotal CF – Commercial Components
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 48 - Version 1.6.b 28
What We Charge For
●
Pivotal RabbitMQ, on PCF
Partner
●
Pivotal Redis
AI Provided
●
…
AI Services (such as
$ Oracle DB,
IaaS Provider
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 49 - Version 1.6.b 29
Pivotal CF: Developer Benefits
• Application Manager
– Start/stop
– Scale
– Services
– Logs
– etc.
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 50 - Version 1.6.b 30
Pivotal CF: Operator Benefits
• Click to Install
• No downtime updates
• Explore install logs
• Click to scale platform
• Built-in high availability
• Built-in platform
monitoring
• Integrated services
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 51 - Version 1.6.b 31
Pivotal CF: Operators View
Install and
Setup High manage
Availability Scale and plan services
capacity
Install
platform
Pivotal CF
Target multiple
clouds
Handle live
upgrades/updates
IaaS
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 52 - Version 1.6.b 32
How can I use Pivotal CF?
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 53 - Version 1.6.b 33
Documentation
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 54 - Version 1.6.b 34
Pivotal Support
• Community forums
– https://groups.google.com/a/cloudfoundry.org/forum/#!forumsearch/
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 55 - Version 1.6.b 35
Summary
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 56 - Version 1.6.b 36
Lab
Explore Cloud Foundry
& Pivotal CF documentation
© Copyright 2016
© Copyright 2014 Pivotal. All rights
Pivotal. All reserved.
rights reserved - 57 - Version 1.6.b 37
Cloud Foundry
Concepts
Terms We Use
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 58 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 59 - Version 1.6.b 2
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 60 - Version 1.6.b 3
Applications
• PaaS exists to deploy applications
– In Cloud Foundry, the application is the unit of deployment
– Developers focus on apps, not runtimes or services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 61 - Version 1.6.b 4
Buildpacks and Manifests
• Buildpacks
– Allow CF to support multiple languages and deployment
environments
• Buildpacks for Java, Ruby, JavaScript …
• Buildpacks for Tomcat, Rails, Node.JS …
• Manifests ---
---
applications:
applications:
– A deployment “blueprint” for -- name:
name: nodetestdh01
nodetestdh01
memory:
memory: 64M
64M
an application instances:
instances: 22
– Repeatable: redeploy using host:
host: crn
crn ## unique
unique
domain:
domain: cfapps.io
cfapps.io
same manifest path:
path: ..
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 62 - Version 1.6.b 5
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 63 - Version 1.6.b 6
Organizations
• Top-most
Domain Organization Quota
administrative unit
• Contains spaces
and users
– Which own routes, Route User Space
applications and
services
• Quotas restrict resources
– For orgs and spaces Application Service
• Domain(s)
– Define routes to apps
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 64 - Version 1.6.b 7
Organizations
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 65 - Version 1.6.b 8
Example Organization
Organizations
Other Other
Orgs Orgs
MyOrg Domains
myorg.net
Memory marco Development
Services
Services jlee
Applications
Routes tara
Production
Services
Applications
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 66 - Version 1.6.b 9
Spaces
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 67 - Version 1.6.b 10
Users and Roles
• Members of an organization
– You can invite users to share your “cloud”
• Have specific roles
– Roles control access to domains and spaces
– Roles therefore control who has permission
• To manage routes (see later slides)
• To deploy applications
• To add/bind/remove services
• Don't need to be CF User to access deployed apps
– Each application does its own user-management
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 68 - Version 1.6.b 11
Organization Roles
• Organization Manager
– Can invite/manage users, select/change the plan, establish
spending limits
• Organization Auditor
– View only access to all org and space info, settings,
reports
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 69 - Version 1.6.b 12
Application Space Roles
• Space Manager
– Can invite/manage users, enable features for a given
space
• Space Developer
– Can create, delete, manage applications and services, full
access to all usage reports and logs
• Space Auditor
– View only access to all space information, settings,
reports, logs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 70 - Version 1.6.b 13
Administrator User / Roles
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 71 - Version 1.6.b 14
Quotas
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 72 - Version 1.6.b 15
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 73 - Version 1.6.b 16
Domains
• Deployed applications are associated with a URL
– All requests to that URL redirect to the application
• Each Cloud Foundry instance has a default app domain
– PWS has cfapps.io
• Custom Domains
– Register your own domain
– Give it to Cloud Foundry to use and manage
• Subdomains
– Each application has a unique sub-domain
• It's URL is therefore sub-domain.domain
• Example: deploy an app to http://myapp.cfapps.io
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 74 - Version 1.6.b 17
Routes
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 75 - Version 1.6.b 18
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 76 - Version 1.6.b 19
Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 77 - Version 1.6.b 20
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 78 - Version 1.6.b 21
Getting Started with
Cloud Foundry
Deploying your First Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 79 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 80 - Version 1.6.b 2
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 81 - Version 1.6.b 3
The Command Line Interface
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 82 - Version 1.6.b 4
Test the CLI Utility Version must be 6 or more
Must remove any earlier
(Ruby) version
• It is called cf
– Open a Command/Shell window
– At the prompt type: cf --version
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 83 - Version 1.6.b 5
Getting Help
• Or cf help <command>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 84 - Version 1.6.b 6
DO NOW – Get Help on a Command
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 85 - Version 1.6.b 7
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 86 - Version 1.6.b 8
Login to Cloud Foundry
• Need to tell cf
– What cloud foundry instance you are using
– What your account details are
– Use cf login Color highlighting
MacOS, Linux only
>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 87 - Version 1.6.b 9
Cloud Foundry URLs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 88 - Version 1.6.b 10
For simplicity, most examples
Cloud Foundry URLs in this section show PWS URLs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 89 - Version 1.6.b 11
Finding the API Endpoint URL
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 90 - Version 1.6.b 12
DO NOW – Login
• Firewall issues?
http://docs.cloudfoundry.org/devguide/installcf/http-proxy.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 91 - Version 1.6.b 13
The .cf Directory
localhost:dev$ ls -l ~/.cf
total 48
-rw------- 1 paulchapman staff 2491 15 Aug 14:06 config.json
-rw-r--r-- 1 paulchapman staff 11737 29 Nov 2013 crash
drwxr-xr-x 3 paulchapman staff 102 12 Sep 2013 logs
-rw-r--r-- 1 paulchapman staff 26 12 Sep 2013 target
-rw-r--r-- 1 paulchapman staff 2084 29 Nov 2013 tokens.yml
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 92 - Version 1.6.b 14
DO NOW – .cf folder
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 93 - Version 1.6.b 15
Current Targets
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 94 - Version 1.6.b 16
Viewing Organization
• Commands
– cf orgs All orgs for current user
– cf org <org-name> Shows specified org
>$ cf org pivotaledu
Getting info for org myorg as user@somedomain.com...
OK
pivotaledu:
domains: cfapps.io
quota: paid (10240M memory limit, Unlimited instance
memory limit, 1000 routes, -1 services,
paid services allowed)
spaces: development, production, staging
space quotas:
>$
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 95 - Version 1.6.b 17
Managing Spaces
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 96 - Version 1.6.b 18
Roadmap
• Get Setup
• Login
• Deploying an Application
• Managing Application Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 97 - Version 1.6.b 19
Deploy Using the CLI
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 98 - Version 1.6.b 20
The cf push Philosophy
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 99 - Version 1.6.b 21
Deploy (push) to Cloud Foundry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 100 - Version 1.6.b 22
Domains and URLs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 101 - Version 1.6.b 23
Examples of Using cf push
Specify unique sub-domain
by adding numbers, initials ...
• Fully specified (recommended)
cf push spring-music -i 1
-m 512M
-n spring-music-678
-p build/libs/spring-music.war
– Deploys war file (specify path if needed)
– 1 instance, 512M memory
– Name: spring-music
• Appears as spring-music in Cloud Foundry
– Hostname: spring-music-678
• Creates URL (PWS): spring-music-678.cfapps.io
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 102 - Version 1.6.b 24
What Happens ?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 103 - Version 1.6.b 25
What Happens - 1 URL: spring-music-678.cfapps.io
Next...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 104 - Version 1.6.b 26
What Happens - “Staging” CF must prepare the
app before its first run
...
Starting app spring-music in org your-org / space development as your-id@company.io...
OK
“Buildpack” selected
-----> Downloaded app package (21M) and executed
-----> Java Buildpack Version: v2.7.1 | https://github.com/cloudfoundry/java-
buildpack#fee275a
-----> Downloading Open Jdk JRE 1.8.0_40 from
https://download.run.pivotal.io/openjdk/lucid/x86_64/openjdk-1.8.0_40.tar.gz (6.1s)
Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.3s)
-----> Downloading Spring Auto Reconfiguration 1.7.0_RELEASE from
https://download.run.pivotal.io/auto-reconfiguration/auto-reconfiguration-1.7.0_RELEASE.jar
(0.2s)
-----> Downloading Tomcat Instance 8.0.20 from
https://download.run.pivotal.io/tomcat/tomcat-8.0.20.tar.gz (1.1s)
Expanding Tomcat to .java-buildpack/tomcat (0.1s)
-----> Downloading Tomcat Lifecycle Support 2.4.0_RELEASE from
https://download.run.pivotal.io/tomcat-lifecycle-support/tomcat-lifecycle-support-
2.4.0_RELEASE.jar (0.0s)
-----> Uploading droplet (73M) Buildpack configures Java
...
Reconfigure Spring
Buildpack creates for cloud environment
Next...
“Droplet” Buildpack obtains Tomcat
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 105 - Version 1.6.b 27
What Happens - “Start”
...
0 of 1 instances running, 1 starting Cloud Foundry runs the
0 of 1 instances running, 1 starting
1 of 1 instances running “Droplet” on a “container”
App started
OK
Showing health and status for app spring-music in org your-org as your-id@company.io...
OK
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 106 - Version 1.6.b 28
Application State and Logs
• Run cf apps
> cf apps
Getting apps in org pivotaledu / space development as kkrueger@pivotal.io...
OK
• cf logs spring-music
> cf logs spring-music
Connected, tailing logs for app spring-music in org pivotaledu / space development as
kkrueger@gopivotal.com...
2014-06-07T23:01:47.68-0400 [RTR] OUT spring-music-678.cfapps.io -
[08/06/2014:03:01:47 +0000] "GET /assets/js/status.js HTTP/1.1" 200 844 "http://spring-
music-678.cfapps.io/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)
AppleWebKit/537.73.11 (KHTML, like Gecko) Version/6.1.1 Safari/537.73.11"
10.10.66.34:64401 vcap_request_id:73037523-63ef-498f-6cd8-d3b48fe69e84
response_time:0.003693009 app_id:314f0434-d2c9-446c-ab4a-6c310878ca80
2014-06-07T23:01:48.47-0400 [RTR] OUT spring-music-678.cfapps.io -
[08/06/2014:03:01:48 +0000] "GET /assets/templates/header.html HTTP/1.1" 200 1060
"http://spring-music-678.cfapps.io/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)
AppleWebKit/537.73.11 (KHTML, like Gecko) Version/6.1.1 Safari/537.73.11"
10.10.66.34:64324 vcap_request_id:39fbb3f2-46fb-4bd7-78d6-8994fafade9f
response_time:0.004132254 app_id:314f0434-d2c9-446c-ab4a-6c310878ca80
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 107 - Version 1.6.b 29
See The Application Running
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 108 - Version 1.6.b 30
Configuring a Deployed Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 109 - Version 1.6.b 31
Stopping and Starting
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 110 - Version 1.6.b 32
Adding / Removing Routes
• Remove mapping
– cf unmap-route <app> <domain> -n <hostname>
– cf unmap-route spring-music cfapps.io -n spring-music-678
• spring-music-678.cfapps.io no longer maps to spring-
music
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 111 - Version 1.6.b 33
Cleaning Up Unused Routes
• Remove route:
– cf delete-route
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 112 - Version 1.6.b 34
Roadmap
• Get Setup
• Login
• Deploying an Application
• Managing Application Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 113 - Version 1.6.b 35
Apps Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 114 - Version 1.6.b 36
Apps Manager Home Page
• At a glance view of all your applications
– Shows current space
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 115 - Version 1.6.b 37
Application state Application Dashboard
YOUR@EMAIL.ADDRESS
Instance Statistics
Application
Information
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 116 - Version 1.6.b 38
Change Mapped URL
1 3
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 117 - Version 1.6.b 39
Stopping and Starting
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 118 - Version 1.6.b 40
Monitoring Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 119 - Version 1.6.b 41
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 120 - Version 1.6.b 42
Lab
Push an existing application to Pivotal CF
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 121 - Version 1.6.b 43
Getting Started with
Cloud Foundry
Deploying via Eclipse or Spring Tool Suite
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 122 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 123 - Version 1.6.b 2
Roadmap
• Get Setup
• Deploying an Application
• Managing Application Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 124 - Version 1.6.b 3
Setting up Eclipse / Spring Tool Suite
• Select Help → Eclipse Marketplace
• Search for Cloud Foundry plugin and install (if need be)
Do this now...
– The install takes time to run.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 125 - Version 1.6.b 4
Setting up a New Server
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 126 - Version 1.6.b 5
Fill in Details of you CF Account
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 127 - Version 1.6.b 6
Roadmap
• Get Setup
• Deploying an Application
• Managing Application Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 128 - Version 1.6.b 7
Deployment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 129 - Version 1.6.b 8
Application details
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 130 - Version 1.6.b 9
What just happened?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 131 - Version 1.6.b 10
Watching it Run
• In the Dashboard
– Double click
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 132 - Version 1.6.b 11
Overview Dashboard Tab
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 133 - Version 1.6.b 12
Applications Tab Application status here
Click URL
Select app first once running
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 134 - Version 1.6.b 13
See Your Application Running in Eclipse
• Eclipse pops up a browser window open at your URL
– Or use the browser of your choice
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 135 - Version 1.6.b 14
Roadmap
• Getting Setup
• Deploying an Application
• Managing Application Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 136 - Version 1.6.b 15
Cloud Foundry Dashboard
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 137 - Version 1.6.b 16
Change Mapped URL
2
• Click pencil (edit) icon
• Can add, edit or remove
URLs
• Save when done
1
4
3
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 138 - Version 1.6.b 17
Choosing Your URL
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 139 - Version 1.6.b 18
Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 140 - Version 1.6.b 19
Memory Allocation
2
1
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 141 - Version 1.6.b 20
Stopping and Starting
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 142 - Version 1.6.b 21
Monitoring Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 143 - Version 1.6.b 22
Summary: Cloud Foundry Dashboard
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 144 - Version 1.6.b 23
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 145 - Version 1.6.b 24
Lab
Deploy an existing application to
Cloud Foundry using Eclipse
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 146 - Version 1.6.b 25
Appendices
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 147 - Version 1.6.b 26
Appendix A: Installing CF Plugin into STS
See: http://docs.cloudfoundry.org/devguide/deploy-apps/sts.html#install-to-sts
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 148 - Version 1.6.b 27
Select Cloud Foundry Integration for Eclipse
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 149 - Version 1.6.b 28
Runs up a Wizard
• Click Next
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 150 - Version 1.6.b 29
Wizard – Step 2
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 151 - Version 1.6.b 30
Wizard – Step 3
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 152 - Version 1.6.b 31
Appendix B: Installing into Eclipse
See: http://docs.cloudfoundry.org/devguide/deploy-apps/sts.html#install-to-eclipse
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 153 - Version 1.6.b 32
Confirm Selected Features
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 154 - Version 1.6.b 33
Last Few Steps
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 155 - Version 1.6.b 34
Logging and
Troubleshooting in
Cloud Foundry
A closer look at practical Cloud Foundry usage
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 156 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 157 - Version 1.6.b 2
Roadmap
• Logging
• Troubleshooting
• How Deployment Happens
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 158 - Version 1.6.b 3
Execution Agent VM
Log Aggregation Architecture ●
Cells in Diego
●
Formerly DEAs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 159 - Version 1.6.b 4
Logging Terminology
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 160 - Version 1.6.b 5
Logging - Sources
• Application Instances
– Logs collected from all
application instances Exec. Agent
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 161 - Version 1.6.b 6
From PCF 1.4
Logging - Sinks
• CLI – Tail
Logging
– Quick, direct way to Server(s)
obtain output
– cf logs <appname> Syslog
Drain(s)
• Third-party log managers Loggregator
Traffic
– Splunk, Logentries, Controller(s)
logstash, Papertrail, etc.
cf App third-
CLI Mgr party
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 162 - Version 1.6.b 7
A Tour of Log Output
Timestamp – Added by
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
Loggregator
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...]
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /info HTTP/1.1" 200 48
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance (index 1) with guid 018.70d-e84f05375859
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...]
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment for Cloud Foundry
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 ({"instances"=>2})
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 163 - Version 1.6.b 8
A Tour of Log Output
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
Log Type / Origin
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...] Where this message came from
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM • org.apache.coyote.AbstractProtocol
API – Cloud Controller start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
– A change in application
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start state
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io• -APP/# - Your
[19:01:09 +0000] "GET Application / Instance
/info HTTP/1.1" 200 48 number
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance•(indexRTR – Router
1) with guid 018.70d-e84f05375859
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...] • CELL – Execution Agent
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
• etc.
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment for Cloud Foundry
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 ({"instances"=>2})
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 164 - Version 1.6.b 9
A Tour of Log Output
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...]
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /info HTTP/1.1" 200 48
Channel
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance (index 1) with guid 018.70d-e84f05375859
• Whether this output came
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...] from “SYSOUT” or “SYSERR”
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment for Cloud Foundry
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 ({"instances"=>2})
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 165 - Version 1.6.b 10
A Tour of Log Output
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...]
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /info HTTP/1.1" 200 48
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance (index 1) with guid 018.70d-e84f05375859
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...]
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
Message
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment for Cloud Foundry
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
• 2014-04-11T14:58:57.44
From the application / component
[APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 ({"instances"=>2})
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 166 - Version 1.6.b 11
A Tour of Log Output
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...]
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /info HTTP/1.1" 200 48
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance (index 1) with guid 018.70d-e84f05375859Instance 0 startup activity
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...] (condensed)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment for Cloud Foundry
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 ({"instances"=>2})
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 167 - Version 1.6.b 12
A Tour of Log Output
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...]
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /info HTTP/1.1" 200 48
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance (index 1) with guid 018.70d-e84f05375859
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...]
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment for Cloud Foundry
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 User requests for
a
({"instances"=>2})
web page on instance 0
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 168 - Version 1.6.b 13
A Tour of Log Output
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...]
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /info HTTP/1.1" 200 48
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance (index 1) with guid 018.70d-e84f05375859
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...]
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment forRequest
Cloud Foundryto scale application
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
• cf scale <appname>
2014-04-11T14:58:57.44 [APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
-i 2
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 ({"instances"=>2})
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 169 - Version 1.6.b 14
A Tour of Log Output
2014-04-11T14:58:41.66 [API] OUT Updated app with guid 018f9a20-f0c9.5375859 ({"state"=>"STARTED"})
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,323 INFO WebApplicationContext:244 - Found 1 …
2014-04-11T14:58:53.32 [APP/0] OUT 18:58:53,324 INFO WebApplicationContext:229 - Successfully resolved …
2014-04-11T14:58:53.52 [APP/0] OUT 18:58:53,527 INFO XmlBeanReader:316 - Loading definitions from class path …
2014-04-11T14:58:54.47 [APP/0] OUT ...]
2014-04-11T14:58:56.24 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.25 [APP/0] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/0] ERR INFO: Initializing Spring for Cloud Foundry
2014-04-11T14:58:57.44 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/0] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
Instance
2014-04-11T14:58:57.45 [APP/0] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start #1 startup activity
2014-04-11T14:58:57.45 [APP/0] ERR INFO: Server startup in 8713 ms
2014-04-11T15:01:09.44 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /info HTTP/1.1" 200 48
2014-04-11T15:01:09.46 [RTR] OUT spring-music-567.cfapps.io - [19:01:09 +0000] "GET /albums HTTP/1.1" 200 4669
2014-04-11T15:03:35.16 [CELL] OUT Starting app instance (index 1) with guid 018.70d-e84f05375859
2014-04-11T15:03:40.43 [APP/1] ERR INFO: Starting Servlet Engine: Apache Tomcat/7.0.52
2014-04-11T14:58:54.47 [APP/1] OUT ...]
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.26 [APP/1] OUT Hibernate: insert into Album (albumId, artist, trackCount, id) values (?, ?, ?, ?, ?, ?, ?)
2014-04-11T14:58:56.38 [APP/1] ERR INFO: Initializing Spring Environment for Cloud Foundry
2014-04-11T14:58:57.44 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.coyote.AbstractProtocol start
2014-04-11T14:58:57.44 [APP/1] ERR INFO: Starting ProtocolHandler ["http-bio-62773"]
2014-04-11T14:58:57.45 [APP/1] ERR Apr 11, 2014 6:58:57 PM org.apache.catalina.startup.Catalina start
2014-04-11T14:58:57.45 [APP/1] ERR INFO: Server startup in 8713 ms
2014-04-11T15:03:35.15 [API] OUT Updated app with guid 018f9a20-f0c9-4b5a-970d-e84f05375859 ({"instances"=>2})
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 170 - Version 1.6.b 15
More Logging
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 171 - Version 1.6.b 16
Accessing Logs
• Recent activity
– cf logs <app_name> --recent
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 172 - Version 1.6.b 17
From PCF 1.6
SSH Access
• Example:
Also requires cf CLI 6.14+
>$ cf ssh pc-spring-music
vcap@7nqelvq2c92:~$ ls
app logs staging_info.yml tmp
vcap@7nqelvq2c92:~$ uname -a
Linux 7nqelvq2c92 3.19.0-33-generic #38~14.04.1-Ubuntu SMP
Fri Nov 6 18:17:28 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 173 - Version 1.6.b 18
Access to Files / Logs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 174 - Version 1.6.b 19
From PCF 1.6 – deploy to
DEA or Diego Runtime? DEAs instead of Cells
• cf-diego plugin to cf
– Allows choice of deployment runtime
• Backwards compatibility for pre-existing users
– Need to setup plugin repo (one time only)
• Then install the new plugin
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 175 - Version 1.6.b 20
DEA or Diego Runtime?
• Procedure:
– Setup your application
• Push with usual options but don't start it
– Then pick preferred runtime and start the app
cf push myapp ... --no-start Use Diego Cells
cf enable-diego
cf start myapp
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 176 - Version 1.6.b 21
Eclipse Remote Systems View
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 177 - Version 1.6.b 22
Eclipse Remote Systems View – cont.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 178 - Version 1.6.b 23
Roadmap
• Logging
• Troubleshooting
• How Deployment Happens
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 179 - Version 1.6.b 24
Troubleshooting applications in Cloud
Foundry
• Troubleshooting Applications in Cloud Foundry can be
hard
– Deployment / push issues
– Runtime issues
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 180 - Version 1.6.b 25
cf apps command
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 181 - Version 1.6.b 26
Events
• cf events <app-name>
– Event log related to you application
> cf events spring-music
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 182 - Version 1.6.b 27
Recent Logs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 183 - Version 1.6.b 28
CF_TRACE
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 184 - Version 1.6.b 29
Common CF Deployment Issues - Java
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 185 - Version 1.6.b 30
Best Practices - Ruby
• Precompile assets
– Recommended to reduce staging time
• Use rails_serve_static_assets gem (Rails 4)
– Sets config.serve_static_assets = true
– Allows populating of CDN, or serving files directly from
application
.cfignore
.cfignore
• Don't push unnecessary files .gitignore
.gitignore
_darcs
_darcs
– List them in .cfignore .DS_Store
.DS_Store
– cf should ignore .cfignore! .git
.git
.hg
.hg
.svn
.svn
/manifest.yml
/manifest.yml
/tmp
/tmp
/logs
/logs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 186 - Version 1.6.b 31
Best Practices – Node.JS {
"name": "myapp",
"version": "0.0.1",
"author": "Your Name",
• package.json mandatory "dependencies": {
– For configuration "express": "3.4.8",
"consolidate": "0.10.0",
• Again. don't push unnecessary files "express": "3.4.8",
"swig": "1.3.2"
– Use .cfignore
},
"engines": {
"node": "0.12.2",
• Specify application's web start "npm": "2.7.4"
command }
}
– Using a Procfile
– Or cf push –command "node myapp.js"
– Or Cloud Foundry deployment manifest
• (covered later)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 187 - Version 1.6.b 32
Controlling Timeouts
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 188 - Version 1.6.b 33
What about IDE Debugging?
• Connecting an IDE to an application running on Cloud
Foundry is basically not possible
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 189 - Version 1.6.b 34
Roadmap
• Logging
• Troubleshooting
• How Deployment Happens
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 190 - Version 1.6.b 35
Deploying App to Cloud Foundry
Push & Staging
Developer
Developer Blobstore
Blobstore CCDB
CCDB
cf push
metadata Cloud
CloudController
Controller
Router
Messaging
Messaging
(NATS)
(NATS)
Cloud
Cloud Foundry
Foundry
EA
EA EA
EA EA
EA EA
EA
1. Establish Route
+ =
2. Stage Application
Diego Enhancement:
Dedicated Execution Agents (EAs) for Staging
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 191 - Version 1.6.b 36
Deploying App to Cloud Foundry
Starting
Developer
Developer Blobstore
Blobstore CCDB
CCDB
cf push
Cloud
CloudController
Controller
Router Auctioneer
Auctioneer
Messaging
Messaging
(NATS)
(NATS)
Cloud
Cloud Foundry
Foundry
EA
EA EA
EA EA
EA EA
EA
1. Establish Route
2. Stage Application Warden Warden
3. Start Application
Diego Enhancement:
Uses Auctioneer component to pick “best” EAs for better load balancing
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 192 - Version 1.6.b 37
Deploying App to Cloud Foundry
Health Management and Running
Users
Users Blobstore
Blobstore CCDB
CCDB
1. Access URL
Cloud
CloudController
Controller Health
Health
Router Management
Management
Subsytem
Subsytem
Messaging
Messaging
(NATS)
(NATS)
Cloud
Cloud Foundry
Foundry
EA
EA EA
EA EA
EA EA
EA
1. Establish Route
2. Stage Application Warden Warden
3. Start Application
4. EAs send heartbeats
(for health monitoring) DIEGO: Uses the “Converger”
DEA: Used a “Health Manager”
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 193 - Version 1.6.b 38
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 194 - Version 1.6.b 39
Lab
Troubleshooting application problems
with Cloud Foundry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 195 - Version 1.6.b 40
Manifests,
Environment
Variables, and Scaling
A closer look at practical Cloud Foundry usage
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 196 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 197 - Version 1.6.b 2
Roadmap
• Manifest Files
• Environment Variables
• Scaling
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 198 - Version 1.6.b 3
Cloud Foundry Manifest file
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 199 - Version 1.6.b 4
Using a Manifest with Push
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 200 - Version 1.6.b 5
YAML Format
• 3 dashes ---
---
applications:
applications:
– Indicate start of document -- name:
name: nodetestdh01
nodetestdh01
memory:
memory: 64M
• Indent with spaces, not tabs! instances:
64M
instances: 22
– Determines hierarchy host:
host: crn
crn ## comment
comment
domain:
domain: cfapps.io
cfapps.io
– Each indent 2 spaces path:
path: ..
## comment
comment
– “-” defines “group”
• Syntax: property: value pairs -- name:
name: nextapp
nextapp ## group
group 22
memory:
memory: 256M
256M
• # starts a one line comment ...
...
• See http://www.yaml.org/spec/1.2/spec.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 201 - Version 1.6.b 6
manifest.yml Example
---
--- • Applications: can describe
applications:
applications: one or more applications
-- name:
name: cf-node-demo
cf-node-demo
command:
command: node
node app.js
app.js • Name: of the app – used in
memory:
memory: 128M
128M
instances:
instances: 11
commands
host:
host: demo-${random-word}
demo-${random-word} • Command: command to run
domain:
domain: cfapps.io
cfapps.io
path:
path: .. (optional)
• Memory ceiling / instances to
run
• Host: your choice, must be
unique (within domain)
– Tip: ${random-word}
• Path: to executable
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 202 - Version 1.6.b 7
Manifest Inheritance
---
--- ---
---
applications:
applications: inherit:
inherit: base-manifest.yml
base-manifest.yml
name:
name: app
app env:
env:
…… FOO:
FOO: foo
foo
……
base-manifest.yml prod-manifest.yml
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 203 - Version 1.6.b 8
Specifying Timeouts
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 204 - Version 1.6.b 9
Manifests and STS – I
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 205 - Version 1.6.b 10
Manifests and STS – II
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 206 - Version 1.6.b 11
Note on Spaces
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 207 - Version 1.6.b 12
Manifest vs CLI
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 208 - Version 1.6.b 13
Roadmap
• Manifest Files
• Environment Variables
• Scaling
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 209 - Version 1.6.b 14
Environment Variables
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 210 - Version 1.6.b 15
Environment Variables - Precedent
Example: ---
---
– cf set-env app FOO fromCLI env:
env:
FOO:
FOO: fromManifest
fromManifest
– cf push applications:
applications:
– Result? 'fromManifest'! name:
name: app
app
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 211 - Version 1.6.b 16
Environment Variables - Persistence
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 212 - Version 1.6.b 17
Environment Variables - Accessing
Access via...
– Java: System.getenv("some_variable");
– Ruby: ENV['some_variable']
– Node.js: process.env.some_variable
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 213 - Version 1.6.b 18
Environment Variables - VCAP_APPLICATION
{"instance_id":"451f045fd16427bb99c895a2649b7b2a",
{"instance_id":"451f045fd16427bb99c895a2649b7b2a",
"instance_index":0,
"instance_index":0,
"host":"0.0.0.0",
"host":"0.0.0.0",
"port":61857,
"port":61857,
"started_at":"2013-08-12
"started_at":"2013-08-12 00:05:29
00:05:29 +0000",
+0000",
"started_at_timestamp":1376265929,
"started_at_timestamp":1376265929,
"start":"2013-08-12
"start":"2013-08-12 00:05:29
00:05:29 +0000",
+0000",
"state_timestamp":1376265929,
"state_timestamp":1376265929,
"limits":{"mem":512,"disk":1024,"fds":16384},
"limits":{"mem":512,"disk":1024,"fds":16384},
...
...
}`
}`
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 214 - Version 1.6.b 19
Environment Variables - VCAP_SERVICES
• Information on all bound services
– JSON formatted object (described later):
{{ "elephantsql":
"elephantsql": [[
{{ "name":
"name": "elephantsql-c6c60",
"elephantsql-c6c60",
"label":
"label": "elephantsql-n/a",
"elephantsql-n/a",
"tags":
"tags": [[ "postgres",
"postgres", "postgresql",
"postgresql", "relational"
"relational" ],
],
"plan":
"plan": "turtle",
"turtle",
"credentials":
"credentials": {{
"uri":
"uri": "postgres://PHxTPn@babar.elephantsql.com:5432/selmbd"
"postgres://PHxTPn@babar.elephantsql.com:5432/selmbd"
}}
}} ],],
"sendgrid":
"sendgrid": [[
{{ "name":
"name": "mysendgrid",
"mysendgrid",
"credentials":
"credentials": {{
"username":
"username": "QvsXMbJ3rK",
"QvsXMbJ3rK",
"password":
"password": "HCHMOYluTv"
"HCHMOYluTv"
}}
}} ]] }}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 215 - Version 1.6.b 20
Integration with Spring
• spring_profiles_active
– “Activates” a profile in a Java/Spring application.
---
---
env:
env:
spring_profiles_active:
spring_profiles_active: dev
dev
another_variable:
another_variable: foo
foo
applications:
applications:
……
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 216 - Version 1.6.b 21
Environment Variables - Management
http://docs.pivotal.io/pivotalcf/devguide/deploy-apps/environment-variable.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 217 - Version 1.6.b 22
Roadmap
• Manifest Files
• Environment Variables
• Scaling
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 218 - Version 1.6.b 23
Scaling Applications
From CLI
cf scale <app-name>
– Reports current scaling
– cf scale <app-name> -i 4 -m 512M -k 1G
– Make 4 instances, each with 512 Meg memory, 1 Gig disk space.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 219 - Version 1.6.b 24
Applications and Resource Limits
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 220 - Version 1.6.b 25
How is CPU Allocated?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 221 - Version 1.6.b 26
Scaling an Application
Cloud
Cloud
cf scale Controller
Controller Blobstore
Blobstore CCDB
CCDB
-i 3
Bulletin
Bulletin The
The“Brain”
“Brain”
Router
Board
Board (Converger
(Converger++Auctioneer)
Auctioneer)
Cell
Cell Cell
Cell Cell
Cell Elastc
Runtme
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 222 - Version 1.6.b 27
Scaling an Application (DEA)
cf scale Cloud
CloudController
Controller Blobstore
Blobstore
-i 3
Messaging
Messaging
(NATS)
(NATS)
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 223 - Version 1.6.b 28
What if I re-push?
• Recommendation:
– Use manifest to store 'default' scaling settings
– OR omit scaling settings from the manifest.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 224 - Version 1.6.b 29
File System Implications
• Implication
– Do not rely on files: transient and not shareable
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 225 - Version 1.6.b 30
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 226 - Version 1.6.b 31
Lab
Using Environment Variables and
Scaling Applications
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 227 - Version 1.6.b 32
Cloud Foundry
Services
Introduction and Overview
What is a Service?
What Services are available?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 228 - Version 1.6.b 1
Roadmap
• Services
• Managed (Marketplace) Services
• Pivotal CF Standard Services
• PWS and App Direct Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 229 - Version 1.6.b 2
Cloud Foundry Services
What is a service?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 230 - Version 1.6.b 3
Cloud Foundry Services
Features and Functionality
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 231 - Version 1.6.b 4
Cloud Foundry Services
Why use a service?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 232 - Version 1.6.b 5
Cloud Foundry Services
Two Types of Services CF Managed
User Managed
• User Defined Services
– Services running external to Cloud Foundry
– Connection information stored and used to connect
– PaaS does not provision resources, only supplies User
connection information.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 233 - Version 1.6.b 6
Accessing External Services ?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 234 - Version 1.6.b 7
Cloud Foundry Services Custom
Custom Services
Also CF Managed
• Custom Built Services
– Custom service created and installed into Cloud Foundry
• Looks like any other managed service once added
• Appears in the Marketplace
– Alternative to user-defined services
• Full integration with CF
• Requirements
– Custom development of service broker by developer
– And operator installation into Cloud Foundry
– Optionally create an Ops Manager Tile
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 235 - Version 1.6.b 8
Services Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 236 - Version 1.6.b 9
Roadmap
• Services
• Managed (Marketplace) Services
• Pivotal Cloud Foundry Standard Services
• PWS and App Direct Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 237 - Version 1.6.b 10
Accessing Managed Services
More planned …
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 238 - Version 1.6.b 11
Managed Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 239 - Version 1.6.b 12
Roadmap
• Services
• Managed (Marketplace) Services
• Pivotal CF Standard Services
• PWS and App Direct Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 240 - Version 1.6.b 13
Pivotal CF Services
What Services are Available
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 241 - Version 1.6.b 14
Pivotal CF Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 242 - Version 1.6.b 15
Pivotal Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 243 - Version 1.6.b 16
Roadmap
• Services
• Managed (Marketplace) Services
• Pivotal Cloud Foundry Standard Services
• PWS and App Direct
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 244 - Version 1.6.b 17
Pivotal Web Services (PWS)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 245 - Version 1.6.b 18
Pivotal Web Services (PWS)
Marketplace Home Page in App Manager Console
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 246 - Version 1.6.b 19
App-Direct
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 247 - Version 1.6.b 20
PWS Cloud-Foundry Services
http://www.appdirect.com
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 248 - Version 1.6.b 21
Running Cloud Foundry On Premise
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 249 - Version 1.6.b 22
Using a Public Service
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 250 - Version 1.6.b 23
Services – Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 251 - Version 1.6.b 24
What You Have Learned
• Services
• Managed (Marketplace) Services
• Pivotal Cloud Foundry Standard Services
• PWS and App Direct Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 252 - Version 1.6.b 25
Cloud Foundry
Services
Creating and Binding Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 253 - Version 1.6.b 1
Roadmap
• Provisioning Services
• Using the CLI
• Using the Pivotal CF App Manager Console
• Binding to a Service
• User Provided Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 254 - Version 1.6.b 2
Service vs. Service Instance
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 255 - Version 1.6.b 3
Provisioning – Operator View
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 256 - Version 1.6.b 4
OPERATOR
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 257 - Version 1.6.b 5
Provisioning – Developer View
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 258 - Version 1.6.b 6
Services Overview – Service Brokers
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 259 - Version 1.6.b 7
Creating a Service Instance
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 260 - Version 1.6.b 8
Roadmap
• Provisioning Services
• Using the CLI
• Using the Pivotal CF App Manager Console
• Binding to a Service
• User Provided Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 261 - Version 1.6.b 9
Finding Available Services
Command Line Interface
example$ cf marketplace
Getting services from marketplace in org pivotaledu / space development as user@domain...
OK
blazemeter free-tier, basic1kmr, pro5kmr, pp10kmr, hv40kmr The JMeter Load Testing Cloud
cleardb spark, boost, amp, shock Highly available MySQL for your Apps
cloudamqp lemur, tiger, bunny, rabbit, panda Managed HA RabbitMQ servers in the cloud
cloudforge free, standard, pro Development Tools In The Cloud
elephantsql turtle, panda, hippo, elephant PostgreSQL as a Service
ironmq pro_platinum, pro_gold, large, medium, small, pro_silver Powerful Durable Message Queueing Service
ironworker large, pro_gold, pro_platinum, pro_silver, small, medium Scalable Background and Async Processing
...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 262 - Version 1.6.b 10
Finding Existing Service Instances
Command Line Interface
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 263 - Version 1.6.b 11
Provisioning a new Service Instance
Command Line Interface
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 264 - Version 1.6.b 12
Finding Existing Service Instances
Command Line Interface
example$ cf services
Getting services in org pivotaledu / space development as user@domain...
OK
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 265 - Version 1.6.b 13
Roadmap
• Provisioning Services
• Using the CLI
• Using the Pivotal CF App Manager Console
• Binding to a Service
• User Provided Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 266 - Version 1.6.b 14
Provisioning Service Instances
GUI
booking-app-123
booking-app-123.cfapp....
M
a
m ys q l
r
k
e
t
p
l
a
c
e
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 267 - Version 1.6.b 15
Finding Available Services
Service Selection
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 268 - Version 1.6.b 16
Provisioning a new Service Instance
Pick a Plan
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 269 - Version 1.6.b 17
Provisioning a new Service Instance
Provision (Create) Service
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 270 - Version 1.6.b 18
Provisioning a new Service Instance
Complete
booking-app-123
booking-app-123.cfapp...
m ys q l
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 271 - Version 1.6.b 19
Roadmap
• Provisioning Services
• Using the CLI
• Using the Pivotal CF App Manager Console
• Binding to a Service
• User Provided Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 272 - Version 1.6.b 20
Accessing Service Instances from an App?
Traditional way
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 273 - Version 1.6.b 21
Accessing Service Instances from an App?
Traditional way
development:
adapter: mysql2 Ruby
• Configuration files encoding: utf8
database: pivotaldb
username: pivotal
password: pivotal
host: myDbHost
port: 3306
datasource {
driverClassName = "com.mysql.jdbc.Driver"
username = "pivotal" Groovy
password = "pivotal"
url = "jdbc:mysql://myDbHost:3306/pivotaldb"
}
datasource.driverClassName="com.mysql.jdbc.Driver"
datasource.username="pivotal" Java
datasource.password="pivotal"
datasource.url="jdbc:mysql://myDbHost:3306/pivotaldb"
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 274 - Version 1.6.b 22
Accessing Service Instances from an App?
The CloudFoundry way
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 275 - Version 1.6.b 23
Example VCAP_SERVICES Property
VCAP_SERVICES=
{ ClearDB is the MySQL instance
cleardb-n/a: [ offered through App Direct
{
name: "cleardb-1",
label: "cleardb-n/a",
plan: "spark",
credentials: {
name: "ad_c6f4446532610ab",
hostname: "us-cdbr-east-03.cleardb.com",
port: "3306",
username: "b5d435f40dd2b2",
password: "ebfc00ac",
uri: "mysql://b5d435f40dd2b2:ebfc00ac@us-cdbr-east-
03.cleardb.com:3306/ad_c6f4446532610ab",
jdbcUrl: "jdbc:mysql://b5d435f40dd2b2:ebfc00ac@us-
cdbr-east-03.cleardb.com:3306/ad_c6f4446532610ab"
}
...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 276 - Version 1.6.b 24
Using a Service – Cloud Foundry
Binding using the CLI
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 277 - Version 1.6.b 25
Using a Service – Cloud Foundry
Binding using a Manifest
---
---
applications:
applications:
-- name:
name: booking-app-456
booking-app-456
memory:
memory: 256M
256M
instances:
instances: 22
host:
host: booking-app-456
booking-app-456
domain:
domain: cfapps.io
cfapps.io
path:
path: target/booking-app.war
target/booking-app.war
## services,
services, one
one per
per line
line
services:
services:
-- mypg
mypg
-- mydb
mydb
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 278 - Version 1.6.b 26
Using a Service
The CloudFoundry way
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 279 - Version 1.6.b 27
Using a Service – Application View
1. Manually
• Manual configuration
– Access VCAP_SERVICES environment variable
– In your code, parse the JSON (see next slide)
• Very low-level but works in most languages
– Fall-back option when options 2 and 3 aren't possible
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 280 - Version 1.6.b 28
Recall: VCAP_SERVICES Property
VCAP_SERVICES=
{ Just a very long string in
cleardb-n/a: [ JSON format
{
name: "cleardb-1",
label: "cleardb-n/a",
plan: "spark",
credentials: {
name: "ad_c6f4446532610ab",
hostname: "us-cdbr-east-03.cleardb.com", Parse to extract
port: "3306", these credentials
username: "b5d435f40dd2b2",
password: "ebfc00ac",
uri: "mysql://b5d435f40dd2b2:ebfc00ac@us-cdbr-east-
03.cleardb.com:3306/ad_c6f4446532610ab",
jdbcUrl: "jdbc:mysql://b5d435f40dd2b2:ebfc00ac@us-
cdbr-east-03.cleardb.com:3306/ad_c6f4446532610ab"
}
...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 281 - Version 1.6.b 29
Using a Service – Application View
2. Custom Library
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 282 - Version 1.6.b 30
Using a Service – Application View
3. Auto-configuration
1) The buildpack
• Some buildpacks support auto-configuration, others do not.
2) The framework
• Spring, Grails, Lift, Rails currently supported.
• NOT (currently) supported for Node.js, Sinatra, Rack …
3) The uniqueness of the service type
• For example, can auto-configure ONE database connection
– CF doesn't know which is which if there are two or more
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 283 - Version 1.6.b 31
Accessing Connection Information
• Recall
– Connection information once bound is in VCAP_SERVICES
– Every application's environment is logged at startup
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 284 - Version 1.6.b 32
Accessing Connection Information - 2
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 285 - Version 1.6.b 33
Roadmap
• Provisioning Services
• Using the CLI
• Using the Pivotal CF App Manager Console
• Binding to a Service
• User Provided Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 286 - Version 1.6.b 34
User Provided Service Instances
http://docs.cloudfoundry.org/devguide/services/user-provided.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 287 - Version 1.6.b 35
Use Cases
User Provided Service Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 288 - Version 1.6.b 36
Defining User Provided Services – 1
name> mydb
Creating user provided service mydb ... OK
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 289 - Version 1.6.b 37
Defining User Provided Services – 2
---
---
applications:
applications:
-- name:
name: spring-music
spring-music
memory:
memory: 512M
512M
instances:
instances: 11
host:
host: spring-music
spring-music
domain:
domain: cfapps.io
cfapps.io
path:
path: build/libs/spring-music.war
build/libs/spring-music.war
services:
services:
mydb:
mydb:
label:
label: user-provided
user-provided
credentials:
credentials:
uri:
uri: postgres://dbuser:dbpass@db.example.com:1234/dbname
postgres://dbuser:dbpass@db.example.com:1234/dbname
username:
username: pivotal
pivotal
password:
password: pivotal
pivotal
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 290 - Version 1.6.b 38
User Provided Services - Accessing
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 291 - Version 1.6.b 39
Example: Application with Multiple Services
VCAP_SERVICES:
VCAP_SERVICES: {{
"rediscloud":
"rediscloud": [[ "user-provided":
"user-provided": [[
{{ {{
"credentials":
"credentials": {{ "credentials":
"credentials": {{
"hostname":
"hostname": "redisvr...com",
"redisvr...com", "uri":
"uri": "http://review.cfapps.io"
"http://review.cfapps.io"
"password":
"password": "wU974wucDT45Jc",
"wU974wucDT45Jc", },
},
"port":
"port": "19016"
"19016" "label":
"label": "user-provided",
"user-provided",
},
}, "name": "reviews",
"name": "reviews",
"label":
"label": "rediscloud",
"rediscloud", "syslog_drain_url":
"syslog_drain_url": "",
"",
"name":
"name": "session-replication",
"session-replication", "tags":
"tags": []
[]
"plan":
"plan": "25mb",
"25mb", },
},
"tags":
"tags": [[ {{
"Data
"Data Stores",
Stores", "credentials":
"credentials": {{
"Cloud
"Cloud Databases",
Databases", "uri":
"uri": "http://products.cfapps.io"
"http://products.cfapps.io"
"Developer
"Developer Tools",
Tools", },
},
"Data
"Data Store",
Store", "label":
"label": "user-provided",
"user-provided",
"key-value",
"key-value", "name":
"name": "products",
"products",
"redis"
"redis" "syslog_drain_url":
"syslog_drain_url": "",
"",
]] "tags": []
"tags": []
}} }}
],
], ]]
}}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 292 - Version 1.6.b 40
What you have learned
• Provisioning Services
– Using the CLI
– Using the Pivotal CF App Manager Console
• Binding to a Service
• User Provided Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 293 - Version 1.6.b 41
Lab
Creating a service and binding to it
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 294 - Version 1.6.b 42
Services
Adding External Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 295 - Version 1.6.b 1
Topics Covered
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 296 - Version 1.6.b 2
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 297 - Version 1.6.b 3
Service Broker
Custom (Managed) Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 298 - Version 1.6.b 4
Cloud Foundry Internet
Architecture
Dynamic Router
• Cloud Controller manages Cloud Controller
service via its service broker
UAA/Login Servers Health Manager
• Broker runs on dedicated node Exec Agent Pool
Service Broker Node(s)
• A broker must define 5 HTTP
Apps
RESTful endpoints
Build Packs
– GET catalog PaaS
User Provided
– PUT new instance Service Instances Logging
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 299 - Version 1.6.b 5
Creating and Binding a Service
Service
DB
DB credentials
CLI
CLI create service (HTTP) Cloud
Cloud create service (HTTP) Service
Service reserve resources Data
Data
Controller
Controller Broker
Broker Service
Service
Cloud Foundry
Router
Runtme (PaaS)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 300 - Version 1.6.b 6
Service Broker
Service Broker Example (MySQL)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 301 - Version 1.6.b 7
Service Broker
Server Broker API
• GET /v2/catalog
– List services and plans available from this broker.
• PUT /v2/service_instances/:instance_id
– Create a new service instance.
• PUT /v2/service_instances/:instance_id/service_bindings/:id
– Create a new binding to a service instance.
• DELETE /v2/service_instances/:instance_id/service_bindings/:id
– Unbind from a service instance.
• DELETE /v2/service_instances/:instance_id
– Delete a service instance
• PATCH /v2/service_instances/:instance_id
– Update service to different plan
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 302 - Version 1.6.b 8
1. Broker Registers Offerings
• On Broker startup
Authenticate Token
Service
CLI
My Service
Cloud (process)
Controller
Browser
Execution
Agent
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 303 - Version 1.6.b 9
2. Broker (un)provisions and (un)binds
This is just
one option
Service
CLI
credentials up to you
Broker VM for Service
(i.e. mysql) Instances
Router
UAA
My Service
Cloud (process)
Controller
Browser
Execution
Agent
Droplet
credentials
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 304 - Version 1.6.b 10
Service Broker
Service Broker Implementation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 305 - Version 1.6.b 11
Service Instance Provisioning Examples
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 306 - Version 1.6.b 12
Service Broker Deployment Models
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 307 - Version 1.6.b 13
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 308 - Version 1.6.b 14
Microservices
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 309 - Version 1.6.b 15
Microservices Explained
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 310 - Version 1.6.b 16
Monolithic Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 311 - Version 1.6.b 17
Microservice Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 312 - Version 1.6.b 18
Developing a Microservice
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 313 - Version 1.6.b 19
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 314 - Version 1.6.b 20
Custom Service Broker – 1
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 315 - Version 1.6.b 21
Custom Service Broker – 2a
• Start with
– https://github.com/spgreenberg/spring-boot-cf-service-broker-mongo
• Then customize...
– Adjust build.gradlefile
– Rename Mongo*Service classes to appropriate names for
your new service broker
– Adjust code in service classes to implement appropriate
backend processing for new service
– Adjust/implement code in Repository classes
– Adjust config code in CatalogConfig class to create a
correct CF service catalog entry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 316 - Version 1.6.b 22
Custom Service Broker – 2b
• Continued …
– Adjust BrokerConfigComponentScan to exclude
BrokerApiVersionConfig class
– Update or disable test-code to ensure correct compilation
– Make any final adjustments to build.gradlefile
– Build and test
– Define/adjust the CF manifest file
– Deploy to CF and test
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 317 - Version 1.6.b 23
Register New Service
Service Broker
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 318 - Version 1.6.b 24
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 319 - Version 1.6.b 25
Resources
• MongoDB: http://www.mongodb.org/downloads
• Managed Services
– http://docs.cloudfoundry.org/services/managing-service-brokers.html
• Spring Service Broker:
– https://github.com/cloudfoundry-community/spring-service-broker
– master branch is the REST framework application
– mongodb branch is an implementation example using
mongodb
• Spring Music App
– https://github.com/scottfrederick/spring-music
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 320 - Version 1.6.b 26
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 321 - Version 1.6.b 27
Introduction to
BuildPacks
Deploying applications written in various
languages
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 322 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 323 - Version 1.6.b 2
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 324 - Version 1.6.b 3
Applications
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 325 - Version 1.6.b 4
The Question:
• Applications can be written in many languages /
frameworks:
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 326 - Version 1.6.b 5
Configuring a Server from scratch
– Operating system
– Runtimes for your software (Java, Ruby, Python, etc.)
– Containers as needed (e.g. Tomcat for Java, Apache HTTPD for
PHP)
– Frameworks as needed (APM tools)
– Application binaries
• Good idea to write a script to do this.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 327 - Version 1.6.b 6
A Buildpack Does the Same Thing
Except the goal is to run on Cloud
Foundry
Buildpack – a combination of
scripts that assembles runtimes,
containers, frameworks, and your Application
application into a droplet
Frameworks
Droplets – run inside Warden Container
Containers Runtime
●
Which run inside Execution Agents
Container (Warden)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 328 - Version 1.6.b 7
The Answer: Buildpacks
• Buildpacks define how assemble a droplet to run a
specific kind of application
• Example:
Java BuildPack
cf push Application WAR
1. Do I know how to deploy
Java WAR this kind of app?
Tomcat
2. Then, build droplet
1. Install Java Java
2. Install Tomcat
3. Create run instructions Operating System
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 329 - Version 1.6.b 8
Buildpacks are Not...
• Buildpacks...
– Are not a special build process for your application
• Buildpacks build droplets
– Do not run on your local machine
• Buildpacks run on CF during the staging process
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 330 - Version 1.6.b 9
Buildpack Structure
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 331 - Version 1.6.b 10
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 332 - Version 1.6.b 11
Execution Agent = Cell (or DEA)
Deploying to CF
Execution Execution
Agent (staging) Agent (run)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 333 - Version 1.6.b 12
Staging and Buildpacks
Application
Execution Runtime
Agent
Operating System
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 334 - Version 1.6.b 13
Available Buildpacks
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 335 - Version 1.6.b 14
Custom Buildpacks
Liberty
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 336 - Version 1.6.b 15
Compatibility
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 337 - Version 1.6.b 16
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 338 - Version 1.6.b 17
Built-In Buildpacks
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 339 - Version 1.6.b 18
Managing Built-In Buildpacks
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 340 - Version 1.6.b 19
Automatic Detection / Explicit Reference
$> cf push
• Application checked against pre-defined buildpacks
• Matching buildpack invoked automatically
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 341 - Version 1.6.b 20
Specify within manifest
---
---
applications:
applications:
-- name:
name: cf-my-app
cf-my-app
host:
host: cf-my-app
cf-my-app
domain:
domain: cfapps.io
cfapps.io
path:
path: target/my-war.war
target/my-war.war
buildpack:
buildpack: https://github.com/cloudfoundry/java-buildpack
https://github.com/cloudfoundry/java-buildpack
• Remember precedence
– Options specified in push command override manifest
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 342 - Version 1.6.b 21
Pushing an Executable
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 343 - Version 1.6.b 22
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 344 - Version 1.6.b 23
Lab
Starting with Buildpacks,
Using a third-party buildpack
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 345 - Version 1.6.b 24
Customizing
BuildPacks
Modifying a buildpack
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 346 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 347 - Version 1.6.b 2
Roadmap
• Buildpack API
• Java Buildpack
• Configure / Extend Java Buildpack
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 348 - Version 1.6.b 3
Buildpack API
• /bin/detect app_directory
– Inspect application bits to determine buildpack applicability
• /bin/compile app_directory cache_directory
– Download and install runtime, container, packages,
libraries; install application bits as necessary
• /bin/release app_directory
– Build application start command
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 349 - Version 1.6.b 4
/bin/detect
Gemfile exists?
package.json exists?
setup.py exists?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 350 - Version 1.6.b 5
/bin/compile
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 351 - Version 1.6.b 6
/bin/compile caching
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 352 - Version 1.6.b 7
/bin/release
addons: []
config_vars: {}
default_process_types:
web: <start command>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 353 - Version 1.6.b 8
Roadmap
• Buildpack API
• Java Buildpack
• Configure / Extend Java Buildpack
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 354 - Version 1.6.b 9
Java Buildpack
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 355 - Version 1.6.b 10
Java Buildpack Concepts
Containers Frameworks
JREs
Java Runtimes
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 356 - Version 1.6.b 11
Java Buildpack Concepts
Containers Frameworks
JREs
OpenJDK, Oracle JDK
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 357 - Version 1.6.b 12
Container Detection Criteria
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 358 - Version 1.6.b 13
Framework Detection Criteria
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 359 - Version 1.6.b 14
/bin/compile Output Example
• Output example:
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 360 - Version 1.6.b 15
See What’s Going On
$> cf files <app-name> app
Log output from buildpack
.java-buildpack.log
.java-buildpack
Sandboxes for each component
open_jdk_jre used during staging
spring_auto_reconfiguration
tomcat
...
META-INF/
WEB-INF/
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 361 - Version 1.6.b 16
Roadmap
• Buildpack API
• Java Buildpack
• Configure / Extend Java Buildpack
• Customization without Forking
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 362 - Version 1.6.b 17
Customization
• You may alter Java buildpack
– Configure artifacts used by standard JREs, Containers,
and Frameworks
– Extend the buildpack with your own JREs, Containers,
and Frameworks
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 363 - Version 1.6.b 18
Customizing Configuration
---
repository_root: "{default.repository.root}/openjdk/{platform}/{architecture}"
version: 1.8.0_+
memory_sizes: repository_root and
metaspace: 64m.. version typically at
memory_heuristics:
the top of each file.
heap: 75
metaspace: 10
stack: 5
native: 10
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 364 - Version 1.6.b 19
Locating Downloads
# http://download.pivotal.io.s3.amazonaws.com/openjdk/lucid/x86_64/index.yml
---
1.8.0_25: https://download.run.pivotal.io/.../x86_64/openjdk-1.8.0_25.tar.gz
1.7.0_71: https://download.run.pivotal.io/.../x86_64/openjdk-1.7.0_71.tar.gz
1.8.0_31: https://download.run.pivotal.io/.../x86_64/openjdk-1.8.0_31.tar.gz
1.7.0_75: https://download.run.pivotal.io/.../x86_64/openjdk-1.7.0_75.tar.gz
1.8.0_40: https://download.run.pivotal.io/.../x86_64/openjdk-1.8.0_40.tar.gz
...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 365 - Version 1.6.b 20
Customization by Configuration: Tomcat
# http://files.example.com/tomcat-custom/index.yml
---
8.0.18: https://download.run.pivotal.io/tomcat/tomcat-8.0.18.tar.gz
8.0.17: https://download.run.pivotal.io/tomcat/tomcat-8.0.17.tar.gz
7.0.59: https://download.run.pivotal.io/tomcat/tomcat-7.0.59.tar.gz
8.0.20: https://download.run.pivotal.io/tomcat/tomcat-8.0.20.tar.gz
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 366 - Version 1.6.b 21
Resource Configuration
resources/tomcat/conf
context.xml
server.xml
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 367 - Version 1.6.b 22
Extending the Buildpack - 1
lib/java_buildpack
jre
container
framework
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 368 - Version 1.6.b 23
Extending the Buildpack - 2
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 369 - Version 1.6.b 24
Extending the Buildpack - 3
• Add new support class to config/components.yml
# Configuration for components to use in the buildpack
---
containers:
- "JavaBuildpack::Container::DistZip"
- "JavaBuildpack::Container::Groovy"
- "JavaBuildpack::Container::JavaMain"
- "JavaBuildpack::Container::PlayFramework"
- "JavaBuildpack::Container::Ratpack"
- "JavaBuildpack::Container::SpringBoot"
- "JavaBuildpack::Container::SpringBootCLI"
- "JavaBuildpack::Container::Tomcat"
- "JavaBuildpack::Container::YOUR-CONTAINER-HERE"
https://github.com/cloudfoundry/java-buildpack
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 371 - Version 1.6.b 26
Roadmap
• Buildpack API
• Java Buildpack
• Configure / Extend Java Buildpack
• Customization without Forking
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 372 - Version 1.6.b 27
Customization without Forking
• Two options:
– JAVA_OPTS variable
– JBP_CONFIG variables
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 373 - Version 1.6.b 28
Change JVM Runtime Options – I
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 374 - Version 1.6.b 29
Change JVM Runtime Options – II
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 375 - Version 1.6.b 30
JBP_CONFIG variables
https://github.com/cloudfoundry/java-buildpack#configuration-and-extension
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 376 - Version 1.6.b 31
Offline Buildpacks
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 377 - Version 1.6.b 32
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 378 - Version 1.6.b 33
Lab
Forking and Customizing the Java
Buildpack
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 379 - Version 1.6.b 34
Cloud Foundry
Architecture
What's Inside the Box?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 380 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 381 - Version 1.6.b 2
Roadmap
• Architectural Components
– Common Components
– Introduction to Elastic Runtime (Diego)
– Elastic Runtime Internals
– Appendix: Previous Elastic Runtime Architecture (DEAs)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 382 - Version 1.6.b 3
Pivotal CF Components HA Zone 1
HA Zone 2
Blobstore CC DB UAA
UAA/ /
Login
LoginServers
Servers
Cloud
Cloud
Controller Service
Service
Controller Loggregator
(CC) Broker(s)
Broker(s)
Router (Gorouter)
(CC)
Load-Balancer
B O S H
Exec – Execution Agent
UAA – User Authorization & Authentication
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 383 - Version 1.6.b 4
Load Balancer (HA Proxy)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 384 - Version 1.6.b 5
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 385 - Version 1.6.b 6
Cloud Controller
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 386 - Version 1.6.b 7
BlobStore
●
Currently NFS mounted storage
●
Or Amazon S3 store
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 387 - Version 1.6.b 8
Cloud Controller Database (CCDB)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 388 - Version 1.6.b 9
Availability Zones
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 389 - Version 1.6.b 10
Service Broker
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 390 - Version 1.6.b 11
Loggregator
Description Responsibilities
●
Master logging process ●
Non-Persistent, temporary log-
●
Accepts logs from application storage
instances ●
Accumulates logs from multiple
●
Accepts logs from other CF sources and aggregates by
components application
●
Make log data available to ●
Provides logs to external sources
external sinks such as cf logs or App Manager
●
Uses Diego's Doppler server console
since CF 1.4 ●
Supports log “drains” to syslog
servers
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 391 - Version 1.6.b 12
UAA and Login Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 392 - Version 1.6.b 13
Cloud Foundry BOSH
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 393 - Version 1.6.b 14
Roadmap
• Architectural Components
– Common components
– Introduction to Elastic Runtime (Diego)
– Elastic Runtime Internals
– Appendix: Previous Elastic Runtime Architecture (DEAs)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 394 - Version 1.6.b 15
What Is DIEGO?
Be careful, many online references still discuss the older DEA architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 395 - Version 1.6.b 16
DIEGO vs DEA
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 396 - Version 1.6.b 17
Roadmap
• Architectural Components
– Common components
– Introduction to Elastic Runtime (Diego)
– Elastic Runtime Internals
– Appendix: Previous Elastic Runtime Architecture (DEAs)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 397 - Version 1.6.b 18
From PCF 1.5
DIEGO Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 398 - Version 1.6.b 19
DIEGO
HA Zone 1
UAA
UAA/ /
Blobstore CC DB
Login
LoginServers
Servers
Cloud Service
Controller
Ω CC
CC Bridge
Bridge Loggregator
Broker(s)
Load-Balancer
Bulletin Board
GoRouter
Garden Garden
Garden
Auctioneer Garden
Docker Garden Docker
B O S H
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 399 - Version 1.6.b 20
CC Bridge Ω
Description Responsibilities
●
Translate app-specific requests ●
Places requests (actions) onto the
into the generic language of LRP Bulletin Board to be actioned by a
and Task Cell's “Executor”
●
For example requests to stage, ●
Ensures that these actions take
start, stop, scale applications place (eventually)
●
Tracks running processes
●
Allows existing CF components to ●
Provides info on running tasks
interact with Diego and LRPs to Cloud Controller
●
Accepts desired state of tasks
and LRPs from Cloud Controller
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 400 - Version 1.6.b 21
Bulletin Board System (BBS) !
Description Responsibilities
●
Holds CF “actions” • Central co-ordination for activities
●
Typical CF actions are to (actions) within CF
start/stop application instances
(LPS) or one-off task processes
●
Essentially an action queue,
currently backed by etcd
●
Other implementations likely
●
Decouples control components
(like the CC) from Diego
●
CC manages applications
●
Diego talks tasks and LRPs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 401 - Version 1.6.b 22
etcd
Description Responsibilities
●
A fast distributed open-source ●
Cluster coordination and state
key-value store management
●
Written in Go and uses the Raft ●
The consistent store at the heart
protocol* of Diego
* https://www.youtube.com/embed/06cTPhi-3_8
© © Copyright2016
Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 402 - Version 1.6.b 23
Converger
Description Responsibilities
●
Makes sure that the system is ●
Compare desired system state
eventually consistent with actual system state
●
Refactoring of instance recovery ●
Take remedial action if they are
functionality that used to be in the different so desired and actual
the old DEA Health Manager and converge
the Cloud Controller ●
Place start (scale up), stop (scale
down) and restart (instance
recovery) requests on the Bulletin
Board
●
Spots requests on BBS too long
●
Forces BBS to try them again
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 403 - Version 1.6.b 24
Auctioneer
Description Responsibilities
●
Determining which Cell to run an ●
Gather state from the appropriate
application instance sources of truth at decision-time
●
Decision uses an Auctioning ●
Run algorithm to decide
placement algorithm
●
Complex because distributed ●
Tell the cell that wins the auction
and asynchronous to either start or stop the
●
Also determines which instance to requested application instance
stop when scaling down ●
By placing the action on the
●
One-off tasks not managed by BBS
auction yet
●
But will in the future
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 404 - Version 1.6.b 25
Auctioneering Algorithm
r
winne
tion
Executor Rep auc Auctioneer
l d an
ho
bid start-auction
Executor Rep
Nsync
Executor Rep
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 405 - Version 1.6.b 26
Cells
Description Responsibilities
●
Secure and fully isolated ●
Participate in app auctions
container ●
Manage apps lifecycle (Executor)
●
Typically a Linux VM ●
Building, starting and stopping
●
But could be a Windows VM Apps as instructed
●
Replace DEAs ●
Manage app containers
●
Periodically broadcast messages ●
Pivotal's secure containers
about their state ●
Or any other container with
●
Typically many Cells in a Cloud same interface
Foundry installation ●
For example to run Docker
●
Runs an Executor internally to ●
Monitor resource pools
manage containers ●
Process, File System, Network,
Memory
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 406 - Version 1.6.b 27
CF and Diego – Full Internal Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 407 - Version 1.6.b 28
Other Internal Components
• Rep • Executor
– Represents Cell – Responsible for executing
– Mediates BBS comms work (actions) given to it
– Bids on tasks – Spins up a Garden
container and executes the
– Schedules them on the
work encoded in Task/LRP
Executor
• Receptor • Metron Agent
– Respond to request for – Monitors all containers on
tasks and desired LRPs Cell
– Fetch information about – Provides logging and
currently running tasks and metrics to Loggregator for
LRP instances all apps/tasks running on
Cell
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 408 - Version 1.6.b 29
Summary
• More information
– https://github.com/cloudfoundry-incubator/diego-design-notes
– Section appendix: DEA Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 409 - Version 1.6.b 30
Original
Appendix: DEA Architecture Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 410 - Version 1.6.b 31
Pivotal CF Components – Original HA Zone 1
HA Zone 2
Blobstore CC DB UAA
UAA/ /
Login
LoginServers
Servers
Cloud
Cloud
Controller Health
Health Doppler Service
Service
Controller
(CC) Manager
Manager (Loggregator
(Loggregator V2)
V2) Broker(s)
Broker(s)
Router (Gorouter)
(CC)
Load-Balancer
Messaging
Messaging(NATS)
(NATS)
Warden Warden
Warden Warden Warden Warden
B O S H
DEA – Droplet Execution Agent
UAA – User Authorization & Authentication
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 411 - Version 1.6.b 32
Droplet Execution Agents (DEA)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 412 - Version 1.6.b 33
Warden Container
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 413 - Version 1.6.b 34
Health Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 414 - Version 1.6.b 35
Messaging (NATS)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 415 - Version 1.6.b 36
Managing
Applications in
Cloud Foundry
A closer look at practical Cloud Foundry usage
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 416 - Version 1.6.b 1
Roadmap
• Log Management
• Application Performance Management
• Autoscaling
• Zero-Downtime Deployments
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 417 - Version 1.6.b 2
Recall: Log Aggregation Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 418 - Version 1.6.b 3
Why Third-Party Log Managers?
• Recommended approach
– Can store far more logging information than CF
– Allow for persistence, storage, searching, analyzing,
metrics
• Variety of third-party log managers supported:
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 419 - Version 1.6.b 4
Connecting to Third-Party Log Managers
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 420 - Version 1.6.b 5
How It Works
1
Logging
1 Server(s)
• All output for app collected
by Logging (Doppler) server
• Loggregator opens socket 2
Loggregator
to HOST:PORT 2 Traffic
Controller(s)
– Sends all log info for app syslog
to socket in syslog format “drain”
• Received by third-party cf App
CLI Mgr
syslog server 3
PORT
syslog 3
server
HOST
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 421 - Version 1.6.b 6
Example: PWS and PaperTrail
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 422 - Version 1.6.b 7
Example: PWS and Papertrail
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 423 - Version 1.6.b 8
Example: PWS and PaperTrail
f) Setup user defined service using Papertrail's URL:
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 424 - Version 1.6.b 9
About Syslog
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 425 - Version 1.6.b 10
Lab
Configuring Third-Party Log
Management Tools with
Cloud Foundry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 426 - Version 1.6.b 11
Roadmap
• Log Management
• Application Performance Management
• Autoscaling
• Zero-Downtime Deployments
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 427 - Version 1.6.b 12
Application Performance Monitoring
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 428 - Version 1.6.b 13
Pivotal Web Services
and New Relic
• PWS offers simple interface to New Relic
– Available as Marketplace Service
– Tracks different instances of application
– Monitors down to the line of code
• How To Use:
– Create New Relic service in desired space
– Bind to desired Application(s)
– Re-stage application
• Java Buildpack includes New Relic Agent, others may not
– APM available as a link from within PWS
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 429 - Version 1.6.b 14
Creating the New Relic Service
• Use App
Manager
Console
• Use cf CLI
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 430 - Version 1.6.b 15
Create Service / Bind Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 431 - Version 1.6.b 16
Access via Manage Link in App Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 432 - Version 1.6.b 17
Lab
Configuring Third-Party Application
Performance Management Tools with
Cloud Foundry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 433 - Version 1.6.b 18
Roadmap
• Log Management
• Application Performance Management
• Autoscaling
• Zero-Downtime Deployments
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 434 - Version 1.6.b 19
Scaling Options
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 435 - Version 1.6.b 20
AutoScaling
• Autoscaling Service
– Must be installed by administrator
– Not available in PWS
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 436 - Version 1.6.b 21
AutoScaling Service – Steps
1) Create the service
1) Select the desired plan
2) Bind to Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 437 - Version 1.6.b 22
AutoScaling – Moving Average
●
Scaling activity based on moving averages
●
Softens effect of temporary spikes Spikes do not
trigger auto-scaling
20%
●
Manual scaling disables AutoScaling
●
Re-enable:
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 438 - Version 1.6.b 23
AutoScaling – Scheduling
●
Autoscaling
events can be
scheduled
●
Changes
autoscaling
behavior on the
given date / time. 2
●
May be single 5
event or recurring
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 439 - Version 1.6.b 24
Roadmap
• Log Management
• Application Performance Management
• Autoscaling
• Zero-Downtime Deployments
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 440 - Version 1.6.b 25
Blue / Green Deployments
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 441 - Version 1.6.b 26
Blue Green Deployment – Existing App
cf push blue -p app.war -n always-reliable -i 4
Users /
Browsers
http://always-reliable.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 442 - Version 1.6.b 27
Blue Green Deployment – New Version
cf push green -p app.war -n temp-route -i 4
Users /
Browsers
http://always-reliable.cfapps.io http://temp-route.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 443 - Version 1.6.b 28
Blue Green Deployment – Duplicate Route
cf map-route green cfapps.io -n always-reliable
Users /
Browsers
http://always-reliable.cfapps.io
http://always-reliable.cfapps.io http://temp-route.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 444 - Version 1.6.b 29
Blue Green Deployment – Disconnect Blue
cf unmap-route blue cfapps.io -n always-reliable
Users /
Browsers
http://always-reliable.cfapps.io
http://temp-route.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 445 - Version 1.6.b 30
Blue Green Deployment – Remove Blue
cf delete blue
Users /
Browsers
http://always-reliable.cfapps.io
http://temp-route.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 446 - Version 1.6.b 31
Canary Deployments
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 447 - Version 1.6.b 32
Canary Deployment – Push The Canary
Users /
Browsers
http://always-reliable.cfapps.io http://always-reliable.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 448 - Version 1.6.b 33
Canary Deployment – Scale Traffic
cf scale green -i 2
cf scale blue -i 3
Users /
Browsers
http://always-reliable.cfapps.io http://always-reliable.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 449 - Version 1.6.b 34
Canary Deployment – Scale Traffic
cf scale green -i 3
cf scale blue -i 2
Users /
Browsers
http://always-reliable.cfapps.io http://always-reliable.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 450 - Version 1.6.b 35
Canary Deployment – Scale Traffic
cf scale green -i 4
cf scale blue -i 1
Users /
Browsers
http://always-reliable.cfapps.io http://always-reliable.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 451 - Version 1.6.b 36
Canary Deployment – Scale Traffic
cf delete blue
Users /
Browsers
http://always-reliable.cfapps.io
Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 452 - Version 1.6.b 37
Lab
Blue / Green Deployment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 453 - Version 1.6.b 38
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 454 - Version 1.6.b 39
Continuous Delivery
and Cloud Foundry
Combining SCM, CD, and CF
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 455 - Version 1.6.b 1
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 456 - Version 1.6.b 2
Defining Terms
• SCM – Source Control Management
– i.e. Version Control
– Tool Examples: Git, SVN, CVS, Clear Case, Perforce, etc.
• CI – Continuous Integration
– Running automated compilation, checks, and tests on a
frequent basis
– Tool Examples: Bamboo, Hudson/Jenkins, Cruise Control,
Team City, Concourse
• CD – Continuous Delivery
– CI + automated deployment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 457 - Version 1.6.b 3
Continuous Integration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 458 - Version 1.6.b 4
Benefits of Continuous Integration
cost
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 459 - Version 1.6.b 5
Continuous Delivery
Compile
Code Quality Checks
Unit Tests
Integration Tests
Packaging
Deployment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 460 - Version 1.6.b 6
Continuous Delivery
You’re doing continuous delivery when:
• Your software is deployable throughout its lifecycle
• Your team prioritizes keeping the software deployable over working on new
features
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 461 - Version 1.6.b 7
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 462 - Version 1.6.b 8
What Is CloudBees?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 463 - Version 1.6.b 9
Example Continuous Delivery Pipeline
Featuring SCM, CloudBees, and Pivotal CF
SCM (GitHub)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 464 - Version 1.6.b 10
Establish Accounts
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 465 - Version 1.6.b 11
CloudBees / Jenkins –
Get Started with Builds
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 466 - Version 1.6.b 12
CloudBees / Jenkins -
New Build
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 467 - Version 1.6.b 13
CloudBees / Jenkins -
Configuration Options
• Many options available, these are just the highlights
– See CloudBees documentation
• Set the name:
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 468 - Version 1.6.b 14
CloudBees / Jenkins -
SCM Integration
• Tell CloudBees about your SCM repository
– We will use GitHub in our example:
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 469 - Version 1.6.b 15
CloudBees / Jenkins
Identify Build Triggers
• Under what circumstances should CloudBees launch the
build process?
Every 10 minutes,
every hour.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 470 - Version 1.6.b 16
CloudBees / Jenkins
Add Post-Build actions to push to Cloud Foundry
• Multiple post
actions
available
– i.e. deploy
Maven
artifacts
• CF will receive
a request for
authorization
• Similar options
to CLI /
Manifest
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 471 - Version 1.6.b 17
Pivotal CF – CloudBees as a Service
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 472 - Version 1.6.b 18
Lab
Deploy to PWS via CloudBees
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 473 - Version 1.6.b 19
High Availability
Keeping Applications Running
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 474 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 475 - Version 1.6.b 2
Roadmap
• BOSH Overview
• The Four Levels of High Availability
– BOSH and Health Monitoring
– Availability Zones
– Handling Application Instance failure (Converger)
• Appendix: The pre-DIEGO Health Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 476 - Version 1.6.b 3
What is BOSH?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 477 - Version 1.6.b 4
Two Perspectives of BOSH
• BOSH is middleware
– Connects the infrastructure to the cluster
• Looking “up”, it is deploying and managing the lifecycle of a
cluster
Cluster
– Create/recreate VMs,
start/restart processes,
enable continuous delivery
...
• Looking “down”, it is using
and abstracting the BOSH
infrastructure
– Cluster doesn't care
what infrastructure it uses Infrastructure
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 478 - Version 1.6.b 5
Installing Cloud Foundry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 479 - Version 1.6.b 6
Ops Manager and BOSH
• Ops Manager is a user interface on top of BOSH
• When you install or make changes in Ops Manager, BOSH-level
changes are being made
– You will see BOSH-related messages in the logs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 480 - Version 1.6.b 7
BOSH Components
Director
• Co-ordinates BOSH (like
CF cloud-controller)
• Maintains own databases
Health Monitor
Worker
• Receives heartbeats from
deployed VMs
CPI
Worker
• Used to run or modify VMs
Cloud Provider Interface
• Interface to underlying IaaS
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 481 - Version 1.6.b 8
Roadmap
• BOSH Overview
• The Four Levels of High Availability
– BOSH and Health Monitoring
– Availability Zones
– Handling Application Instance failure (Converger)
• Appendix: The pre-DIEGO Health Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 482 - Version 1.6.b 9
High Availability
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 483 - Version 1.6.b 10
Scenario 1: Component VM Failure
desired
state
Alert: VM down
2
3
desired
state
1
actual state
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 484 - Version 1.6.b 11
Scenario 1: Component VM Failure Fixed
stemcell
4
5
Worker desired
state
6 7
actual state
CPI
Failed VM restored
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 485 - Version 1.6.b 12
Scenario 2: Component Process Failure
notification 1
Component
process fails
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 486 - Version 1.6.b 13
Roadmap
• BOSH Overview
• The Four Levels of High Availability
– BOSH and Health Monitoring
– Availability Zones
– Handling Application Instance failure (Converger)
• Appendix: The pre-DIEGO Health Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 487 - Version 1.6.b 14
Application High Availability
• Cloud Foundry will scale application instances across
Availability Zones
• Zones correspond to independent infrastructure
segments
– Such as different racks, or
even different data centers
• Provide physical App Execution App Execution
isolation & redundancy inst-1 inst-2
– Feature of the IaaS layer inst-3 inst-4
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 488 - Version 1.6.b 15
Scenario: Availability Zone Failure
cf push my-app -i 4
• If one zone fails, the
application instances in
the other zone pick up
the load
– No Outage
X
App Execution App Execution
AZ-1 AZ-2
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 489 - Version 1.6.b 16
Roadmap
• BOSH Overview
• The Four Levels of High Availability
– BOSH and Health Monitoring
– Availability Zones
– Handling Application Instance failure (Converger)
• Appendix: The pre-DIEGO Health Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 490 - Version 1.6.b 17
Converger (DIEGO)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 491 - Version 1.6.b 18
Health Management
1. Applications run within containers on Cells
2. Cells send heartbeat messages, messages sent to Converger
3. Converger obtains “desired state” from Cloud Controller (from CC DB)
4. Does “desired state” = “actual state”? Yes
Blobstore CC DB
Desired State Actual State
Cloud
Cloud
Controller Converger
Converger
Controller
Router
Messaging
Messaging
Cell
Cell Cell
Cell Cell
Cell Cell
Cell
Warden Warden Warden Warden
Warden Warden
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 492 - Version 1.6.b 19
Health Management – Detecting Failures
1. What if an application crashes X?
2. Cells send heartbeat messages, messages sent to Converger
3. Converger obtains “desired state” from Cloud Controller
4. “Desired state” = “actual state”? No
Blobstore CC DB
Desired State Actual State
Cloud
Cloud
Controller Converger
Converger
Controller
Router
Messaging
Messaging
Cell
Cell Cell
Cell Cell
Cell Cell
Cell
Warden Warden Warden Warden
X
Warden Warden
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 493 - Version 1.6.b 20
Health Management - Replacing an Application
1. Converger puts new instance request on Bulletin Board
2. Auctioneer accepts request and conducts and auction
3. Auctioneer tells winning Cell to run Droplet in a new container
Blobstore CC DB
Desired State Actual State
Cloud
Cloud Bulletin
Bulletin
Board Converger
Converger
Controller
Controller
Start new instance of
Router
Auctioneer
Auctioneer application “Y”
Cell
Cell Cell
Cell Cell
Cell Cell
Cell ✔
Warden Warden Warden Warden
Warden Warden
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 494 - Version 1.6.b 21
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 495 - Version 1.6.b 22
Roadmap
• BOSH Overview
• The Four Levels of High Availability
– BOSH and Health Monitoring
– Availability Zones
– Handling Application Instance failure
• Appendix: Health Manager
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 496 - Version 1.6.b 23
Health Manager (DEA)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 497 - Version 1.6.b 24
Health Management – DEAs
1. Applications run within containers on DEAs
2. DEAs send heartbeat messages, messages sent to Health Manager
3. Health Manager obtains “desired state” from Cloud Controller
4. Does “desired state” = “actual state”? Yes
Blobstore CC DB
Desired State Actual State
Cloud
Cloud Health
Health
Controller
Controller Manager
Manager
Router
Messaging
Messaging(NATS)
(NATS)
DEA
DEA DEA
DEA DEA
DEA DEA
DEA
Warden Warden Warden Warden
Warden Warden
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 498 - Version 1.6.b 25
Health Management – Detecting Failures
1. What if an application crashes X?
2. DEAs send heartbeat messages, messages sent to Health Manager
3. Health Manager obtains “desired state” from Cloud Controller
4. “Desired state” = “actual state”? No
Blobstore CC DB
Desired State Actual State
Cloud
Cloud Health
Health
Controller
Controller Manager
Manager
Router
Messaging
Messaging(NATS)
(NATS)
DEA
DEA DEA
DEA DEA
DEA DEA
DEA
Warden Warden Warden Warden
X
Warden Warden
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 499 - Version 1.6.b 26
Health Management - Replacing an Application
1. Health Manager instructs Cloud Controller
2. Cloud Controller clones Droplet into container on DEA
Blobstore CC DB
Desired State Actual State
Cloud
Cloud Health
Health
Controller
Controller Start new instance of Manager
Manager
application “Y”
Router
Messaging
Messaging(NATS)
(NATS)
DEA
DEA DEA
DEA DEA
DEA DEA
DEA
Warden Warden Warden Warden
Warden Warden
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 500 - Version 1.6.b 27
Designing
Applications for
Cloud Foundry
Writing Applications that Scale
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 501 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 502 - Version 1.6.b 2
Roadmap
• 12-Factor Applications
• Design Guidelines
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 503 - Version 1.6.b 3
Developer Topics / Application Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 504 - Version 1.6.b 4
Roadmap
• 12-Factor Applications
• Design Guidelines
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 505 - Version 1.6.b 5
12-Factor Application
• http://12factor.net
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 506 - Version 1.6.b 6
12-Factor Application
I. Codebase II. Dependencies III. Configuration
One codebase tracked Explicitly declare and Store config in the
in SCM, many deploys isolate dependencies environment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 507 - Version 1.6.b 7
12-Factor Application
I. Codebase II. Dependencies III. Configuration
One codebase tracked Explicitly declare and Store config in the
in SCM, many deploys isolate dependencies environment
• Codebase
– An application has a single codebase
• Multiple codebase = distributed system (not an app)
– Each component in a codebase can (should) be an app
– Tracked in version control
• Git, Subversion, Mercurial, etc.
– Multiple Deployments
• i.e. development, testing, staging, production, etc.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 508 - Version 1.6.b 8
12-Factor Application
I. Codebase II. Dependencies III. Configuration
One codebase tracked Explicitly declare and Store config in the
in SCM, many deploys isolate dependencies environment
• Dependencies
– Packaged as jars (Java), RubyGems, CPAN (Perl)
– Declared in a Manifest
• Maven POM, Gemfile / bundle exec, etc.
– No reliance on specific system tools
• i.e. Linux tool not available on Windows
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 509 - Version 1.6.b 9
12-Factor Application
I. Codebase II. Dependencies III. Configuration
One codebase tracked Explicitly declare and Store config in the
in SCM, many deploys isolate dependencies environment
• Configuration
– Separate from the code
– Also separate from the application
• i.e. DB credentials, hostnames, passwords
• Acid Test – could the codebase be made open source?
• Internal wiring (i.e. Spring configuration) considered part of
codebase.
– Environment Variables recommended.
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 510 - Version 1.6.b 10
12-Factor Application
IV. Backing Services V. Build, Release, Run VI. Processes
Treat backing services Strictly separate build Execute app as
as attached resources and run stages stateless processes
• Backing Services
– Service consumed by app as part of normal operations
• DB, Message Queues, SMTP servers
• May be locally managed or third-party managed
– Services should be treated as resources
• Connected to via URL / configuration
• Swappable (change in-memory DB for MySQL)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 511 - Version 1.6.b 11
12-Factor Application
IV. Backing Services V. Build, Release, Run VI. Processes
Treat backing services Strictly separate build Execute app as
as attached resources and run stages stateless processes
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 512 - Version 1.6.b 12
12-Factor Application
IV. Backing Services V. Build, Release, Run VI. Processes
Treat backing services Strictly separate build Execute app as
as attached resources and run stages stateless processes
• Processes
– One or more discrete running processes
– Stateless
• Processes should not store internal state (HTTP Sessions)
– Shared Nothing
• Data needing to be shared should be persisted
– Memory / local tmp storage considered volatile
– Processes may intercommunicate via messaging /
persistent storage
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 513 - Version 1.6.b 13
12-Factor Application
VII. Port binding VIII. Concurrency IX. Disposability
Export services via port Scale out via the Maximize robustness
binding process model with fast startup and
graceful shutdown
• Port Binding
– App should not need a “container”
• Java App Server, Apache HTTPD for PHP ...
• PaaS now takes that role
– Apps should export HTTP as a service
• Define as a dependency (#2)
– Tornado (Python), Thin (Ruby), embedded Jetty/Tomcat (Java)
• Execute at runtime
– One App can become another App's service (#4, #6)
http://www.grahambrooks.com/2014/04/07/container-less-web-applications.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 514 - Version 1.6.b 14
12-Factor Application
VII. Port binding VIII. Concurrency IX. Disposability
Export services via port Scale out via the Maximize robustness
binding process model with fast startup and
graceful shutdown
• Concurrency
– Processes are first class citizens
• Like Unix service daemons
• Unlike Java threads
– Individual processes are free to multithread
• BUT a VM can only get so large (vertical scaling).
• Must be able to span multiple machines (horizontal scaling)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 515 - Version 1.6.b 15
12-Factor Application
VII. Port binding VIII. Concurrency IX. Disposability
Export services via port Scale out via the Maximize robustness
binding process model with fast startup and
graceful shutdown
• Disposability
– Processes should be disposable
• Remember, they're stateless!
– Should be quick to start and stop
• Should exit gracefully / finish current requests.
• Or should be idempotent / reentrant
– Enhances scalability and fault tolerance
– Design crash-only software
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 516 - Version 1.6.b 16
12-Factor Application
X. Dev/prod parity XI. Logs XII. Admin processes
Keep dev, staging, prod Treat logs as event Run admin / mgmt tasks
as similar as possible streams as one-off processes
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 517 - Version 1.6.b 17
12-Factor Application
X. Dev/prod parity XI. Logs XII. Admin processes
Keep dev, staging, prod Treat logs as event Run admin / mgmt tasks
as similar as possible streams as one-off processes
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 518 - Version 1.6.b 18
12-Factor Application
X. Dev/prod parity XI. Logs XII. Admin processes
Keep dev, staging, prod Treat logs as event Run admin / mgmt tasks
as similar as possible streams as one-off processes
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 519 - Version 1.6.b 19
12-Factor Application
I. Codebase II. Dependencies III. Configuration
One codebase tracked Explicitly declare and Store config in the
in SCM, many deploys isolate dependencies environment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 520 - Version 1.6.b 20
Roadmap
• 12-Factor Applications
• Design Guidelines
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 521 - Version 1.6.b 21
Application Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 522 - Version 1.6.b 22
Load Balancing Router
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 523 - Version 1.6.b 23
Session Management
1 Requests stick to
Router
previous session
3 2 Server dies
X
Server Server Server
2
S2
... 3 New container &
server started
S1 S3 1 S7 4
S6 4 New session – old
S5 S4
session lost
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 524 - Version 1.6.b 24
Session Management
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 525 - Version 1.6.b 25
Local File Access
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 526 - Version 1.6.b 26
Logging
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 527 - Version 1.6.b 27
Resources
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 528 - Version 1.6.b 28
SSH since PCF 1.6
Port Limitations
Router
X
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 529 - Version 1.6.b 29
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 530 - Version 1.6.b 30
Spring and Cloud
Applications
Making JVM cloud applications easier
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 531 - Version 1.6.b 1
Overview
• Note
– Spring IO, Spring Boot are not essential for a Cloud
application
• But they simplify code and dependency management
• So cloud deployment is much easier
– We will rely on them in later sections and labs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 532 - Version 1.6.b 2
Roadmap
• Spring IO
• Spring Boot
• Profiles
• Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 533 - Version 1.6.b 3
What is Spring IO?
Conflict!
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 534 - Version 1.6.b 4
Spring IO
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>1.0.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Use Gradle if you prefer
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 535 - Version 1.6.b 5
Using Spring IO
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 536 - Version 1.6.b 6
What Dependencies are Available?
http://docs.spring.io/platform/docs/current/reference/htmlsingle/#appendix-
dependency-versions
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 537 - Version 1.6.b 7
Roadmap
• Spring IO
• Spring Boot
• Profiles
• Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 538 - Version 1.6.b 8
What is Spring Boot?
• It is not:
– A code generator
– An IDE plugin
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 539 - Version 1.6.b 9
Opinionated Runtime?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 540 - Version 1.6.b 10
Spring Boot Demo
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 541 - Version 1.6.b 11
Spring Boot Dependency Management
Parent POM specifies
dependency versions
• How it works (Maven Example):
<parent>
<groupId>org.springframework.boot</groupId>
Resolves JARS:
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RELEASE</version>
●
spring-boot
</parent> ●
spring-core
spring-context
●
<dependencies> ●
spring-aop
<dependency> ●
aopalliance
<groupId>org.springframework.boot</groupId> ● spring-beans
<artifactId>spring-boot-starter</artifactId>●
</dependency>
logback-core
</dependencies>
●
plus ~10 more ...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 542 - Version 1.6.b 12
Spring Boot – Adding Dependencies
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId> Adds JARS:
</dependency> ●
spring-web
<dependency> ●
spring-webmvc
<groupId>org.springframework.boot</groupId> ●
jackson-databind
<artifactId>spring-boot-starter-web</artifactId>
●
hibernate-validator
</dependency>
</dependencies>
●
tomcat-embed
●
plus transitive
dependencies
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 543 - Version 1.6.b 13
Spring Boot JPA Example
Starter dependency set
• Dependencies for RDBMS application:
JDBC, JPA, Hibernate
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency> HSQL Database
</dependencies>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 544 - Version 1.6.b 14
Programming Spring Boot
• Run application using a main() method 1
– Like we used to before containers!
• @SpringBootApplication 2
– Enables automatic configuration: @EnableAutoConfiguration
• Spring Boot scans classpath, setting up typical defaults
– Marks class as a @Configuration class
– Enabled @ComponentScan from current base package
• SpringApplication class 3
– Initiates Spring Boot
– Tells Spring Boot which class to start with
• Usually this class 1 2 3 see next slide ….
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 545 - Version 1.6.b 15
Example Spring Boot Application
@Configuration +
@EnableAutoConfiguration +
@ComponentScan
2 @SpringBootApplication
Database setup
@ImportResource("classpath:config/db.xml")
public class AccountMain {
Get Spring bean
@Autowired AccountService accountService;
// Do something ...
accountService.someMethod();
}
} Note: Integrates with Java Config, annotated
DI and/or XML configuration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 546 - Version 1.6.b 16
Web Application using Spring Boot
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 547 - Version 1.6.b 17
Run as a WAR
• Two Steps:
– Change Packaging to war: <packaging>war</packaging>
– Extend Spring Boot's Servlet Initializer
@SpringBootApplication
public class WebMain extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder
configure(SpringApplicationBuilder application) {
return application.sources(WebMain.class);
}
}
No WEB.XML! (Unless you want)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 548 - Version 1.6.b 18
Overriding Defaults
• No Problem!
– Simply override the dependencies (see next)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 549 - Version 1.6.b 19
Overriding Defaults – Option 1
...
</dependencies>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 550 - Version 1.6.b 20
Overriding Defaults – Option 2a
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 551 - Version 1.6.b 21
Overriding Defaults – Option 2b
@Configuration
public class JpaConfig {
@Bean
public EntityManagerFactoryBean emf (DataSource dataSource) {
JpaVendorAdapter adapter = new EclipseLinkJpaVendorAdapter();
// Set desired properties.
LocalContainerEntityManagerFactoryBean emfb =
new LocalContainerEntityManagerFactoryBean();
emfb.setDataSource(dataSource);
emfb.setPersistenceUnitName("account");
emfb.setJpaProperties(props);
emfb.setJpaVendorAdapter(adapter);
return emfb;
}
} Spring Java Config – remember
to enable component-scanning
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 552 - Version 1.6.b 22
Spring Boot Maven Properties
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependencies/pom.xml
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 553 - Version 1.6.b 23
Spring Boot Application Properties
spring:
application.yml
datasource:
url: jdbc:mysql://localhost/test
username: dbuser
password: dbpass
driver-class-name: com.mysql.jdbc.Driver No tabs!
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 554 - Version 1.6.b 24
Roadmap
• Spring IO
• Spring Boot
• Profiles
• Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 555 - Version 1.6.b 25
Spring Profiles
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 556 - Version 1.6.b 26
Example Profiles
Transfer
ApplicationContext
Account
Service Service
Beans with Account
Other
Customer
no profile Repository Repository web
Other
always Controller
available Other Other
ErrorHandler
dev
dataSource prod
qa
Connection dataSource
dataSource
Factory
Connection Connection
Performance Factory
Factory
Monitor
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 557 - Version 1.6.b 27
Defining Profiles
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 558 - Version 1.6.b 28
Quiz:
Which of the Following is/are Selected?
-Dspring.profiles.active=jpa
? ? ?
@Configuration @Configuration @Configuration
public class @Profile("jpa") @Profile("jdbc")
Config { ...} public class public class
JpaConfig JdbcConfig
{ ...} { ...}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 559 - Version 1.6.b 29
Activating Profiles For a Test
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 560 - Version 1.6.b 30
Activate Profiles
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 561 - Version 1.6.b 31
Roadmap
• Spring IO
• Spring Boot
• Profiles
• Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 562 - Version 1.6.b 32
Spring Cloud
http://projects.spring.io/spring-cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 563 - Version 1.6.b 33
Spring Cloud Connectors Summary
// Cloud properties:
Properties p = cloud.getCloudProperties();
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 564 - Version 1.6.b 34
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 565 - Version 1.6.b 35
Java Applications
and the Cloud
Building Applications for Cloud Deployment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 566 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 567 - Version 1.6.b 2
Roadmap
• Cloud-Friendly Applications
• Session Handling
• Configuration
• Debugging
• Local Development
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 569 - Version 1.6.b 4
Leveraging Spring
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 570 - Version 1.6.b 5
Tuning Java for Cloud Foundry
http://support.run.pivotal.io/entries/80755985-How-do-I-size-my-Java-or-JVM-based-applications-
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 571 - Version 1.6.b 6
Cloud-Friendly Java Applications
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 572 - Version 1.6.b 7
Roadmap
• Cloud-Friendly Applications
• Session Handling
• Configuration
• Debugging
• Local Development
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 573 - Version 1.6.b 8
Managing State is Hard
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 574 - Version 1.6.b 9
Option 1: Manual Session Management
Replace HTTP Sessions by Redis
• Old code
session.setAttribute("shoppingCart", shoppingCart);
...
Cart shoppingCart = (Cart) Session.getAttribute("shoppingCart");
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 575 - Version 1.6.b 10
Option 2: Spring's Session Abstraction
• What?
– HTTP request is wrapped
• All methods using session data overridden to use the session
from SessionRepository instead
– Any session changes automatically persisted
• Why?
– If process fails, session data safe in Session Repository
– Servlet code unchanged
• How?
– Define a Redis connection (only implementation so far)
– Use @EnableRedisHttpSession
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 576 - Version 1.6.b 11
How It Works
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 577 - Version 1.6.b 12
Define a Session Filter – XML 1
• Using web.xml
<filter>
<filter-name>sessionRepositoryFilter</filter-name>
<filter-class>...DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionRepositoryFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
The “classic” XML Configuration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 578 - Version 1.6.b 13
Spring Configuration – XML 2
@EnableRedisHttpSession // <1>
public class RedisHttpSessionConfig {}
<beans>
<context:annotation-config/>
<bean class="org.springframework.data.redis.connection.
jedis.JedisConnectionFactory"/>
<bean class="sample.RedisHttpSessionConfig"/>
</beans>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 579 - Version 1.6.b 14
Configuration – Java
@Configuration
@EnableRedisHttpSession
public class Config {
@Bean
public JedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory();
}
}
import org.springframework.session.web.
context.AbstractHttpSessionApplicationInitializer;
public Initializer() {
super(Config.class); // Can list multiple classes
}
} Extends WebApplicationInitializer – runs
a Spring Web app using Servlet 3 configuration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 580 - Version 1.6.b 15
How Does It Work?
• AbstractHttpSessionApplicationInitializer
sets up a DelegatingFilterProxy
– Only do this when not using web.xml
• @EnableRedisHttpSession creates
– The sessionRepositoryFilter
– A RedisOperationsSessionRepository
• Implements SessionRepository using Redis
Redis
Jedis
Session Operations Redis
Connection
Repository Session Template
Factory
Repository
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 581 - Version 1.6.b 16
Configuring Redis
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 582 - Version 1.6.b 17
Servlet Code
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 583 - Version 1.6.b 18
Option 3: Buildpack Does It For You
https://github.com/cloudfoundry/java-buildpack/blob/master/docs/container-tomcat.md
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 584 - Version 1.6.b 19
Option 3: Session Replication
Auto-Configured by Java Buildpack
• How it works
– HTTP Session data automatically persisted to service
– If application instance fails, new instance fetches session
data from replication service automatically
– Same as option 2, but no configuration needed
• Implementations
– Redis: Normal Redis service
• Service must be called session-replication
– Gemfire Session State Caching
• Custom Gemfire service specifically for session replication
• http://docs.pivotal.io/ssc-gemfire/using_the_data_service.html
•
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 585 - Version 1.6.b 20
Roadmap
• Cloud-Friendly Applications
• Session Handling
• Configuration
• Debugging
• Local Development
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 586 - Version 1.6.b 21
Shared Files are also Shared State
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 587 - Version 1.6.b 22
Configuration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 588 - Version 1.6.b 23
Use Classpath Resources
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 589 - Version 1.6.b 24
Configuration from Environment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 590 - Version 1.6.b 25
Configuration and Spring Boot
@Value("${test.property}")
Or without Spring Boot: String testProperty;
@Value("${TEST_PROPERTY}")
@Bean SomeObject myBean() { ... }
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 591 - Version 1.6.b 26
Review: Accessing Configuration
http://docs.pivotal.io/pivotalcf/devguide/deploy-apps/environment-variable.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 592 - Version 1.6.b 27
JAVA_OPTS
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 593 - Version 1.6.b 28
Roadmap
• Cloud-Friendly Applications
• State Considered Evil
• Configuration
• Debugging
• Local Development
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 594 - Version 1.6.b 29
Java Debugging via Eclipse
Router
X
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 595 - Version 1.6.b 30
Java Debugging via Eclipse
• General Process:
– Debug your Eclipse project using a Remote Java
Application, connection type as standard socket listener
– Push app with environment variable:
• JAVA_OPTS: -agentlib:jdwp=transport=dt_socket,address=<IP>:<PORT>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 596 - Version 1.6.b 31
Java Buildpack Troubleshooting
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 597 - Version 1.6.b 32
Jolokia: JMX over HTTP
• Configure as a Java
servlet
• Or run as JVM agent
(if no container)
• To access
– http://<your-app-url>/jolokia/read/<OBJECT-NAME>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 599 - Version 1.6.b 34
CF
• Procedure
– Bind Insight service to your application
– Push app using customized Java Buildpack
• Uses tc Server and detects Insight service
– See https://network.pivotal.io
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 600 - Version 1.6.b 35
Roadmap
• Cloud-Friendly Applications
• State Considered Evil
• Configuration
• Debugging
• Local Development
(( ))
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 601 - Version 1.6.b 36
Local Deployment, Cloud Production
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 602 - Version 1.6.b 37
Local Deployment, Cloud Production
@Profile("cloud")
@Configuration
public static class DbConfig {
@Bean
DataSource dataSource() {…}
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 603 - Version 1.6.b 38
Local Deployment, Cloud Production
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 604 - Version 1.6.b 39
Running and Debugging
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 605 - Version 1.6.b 40
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 606 - Version 1.6.b 41
Lab
Using sessions and environment
variables
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 607 - Version 1.6.b 42
Using Spring Cloud
Connectors
Building Applications for Cloud Deployment
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 608 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 609 - Version 1.6.b 2
Roadmap
• Introduction
• Service Binding: Auto-Configuration
• Service Binding: Manually
• Extending Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 610 - Version 1.6.b 3
Spring Cloud
http://projects.spring.io/spring-cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 611 - Version 1.6.b 4
Spring Cloud Connectors
http://cloud.spring.io/spring-cloud-connectors
© © Copyright2016
Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 612 - Version 1.6.b 5
Spring Cloud Connectors
Application
Service Connector Service Information
Information
Cloud Connector
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 613 - Version 1.6.b 6
Spring Cloud Connectors – Concepts
• Cloud Connector
– Allows Spring Cloud to work with any Cloud
– Currently Cloud Foundry and Heroku implemented
• Service Connector
– Represents a connection to a service
– Such as a SQL DataSource
• Service Information
– The underlying service such as host, port, and credentials.
• Application information
– About the application and its running instance(s)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 614 - Version 1.6.b 7
Roadmap (continued)
• Introduction
• Service Binding: Auto-Configuration
• Service Binding: Manually
• Extending Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 615 - Version 1.6.b 8
Service Binding
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 616 - Version 1.6.b 9
Auto Configuration
• How it works
– Buildpack adds Spring auto-reconfiguration JAR to Droplet
– Modifies ApplicationContext at startup
• Activates “cloud” Profile
• Exposes CF Environment Variables as PropertySource
– Bean Post-Processors find beans defining services
• Transparently replaces bean definitions
– Reconfigures JDBC, Hibernate, JPA, MongoDB,
RabbitMQ, and Redis resources
– Uses Spring Cloud Connectors project
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 618 - Version 1.6.b 11
Auto Configuration Restrictions
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 619 - Version 1.6.b 12
Roadmap (continued)
• Introduction
• Service Binding: Auto-Configuration
• Service Binding: Manually
• Extending Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 620 - Version 1.6.b 13
Manual Configuration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 621 - Version 1.6.b 14
Service Binding
• Using Spring Cloud
– Java Config: extend AbstractCloudConfig
@Configuration
@Profile("cloud") No extra
public class DbConfig extends AbstractCloudConfig { configuration –
see next slide
@Bean(name = "dataSource")
public DataSource dataSourceRemote() {
return cloud().getServiceConnector
("account-db", DataSource.class, null);
}
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 622 - Version 1.6.b 15
Configuring the Service
DataSource inventoryDataSource =
cloud.getSingletonServiceConnector
(DataSource.class, serviceConfig);
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 623 - Version 1.6.b 16
Java Configuration
@Configuration
public class DbConfig extends AbstractCloudConfig {
cloud profile set
@Profile("cloud")
@Bean(name = "dataSource") by Java Buildpack
public DataSource dataSourceRemote() {
return cloud().getServiceConnector
("postgres-db", DataSource.class, null);
}
Profile when NOT
@Profile("!cloud") running in the cloud
@Bean(name = "dataSource", destroyMethod = "close")
public DataSource dataSourceEmbedded() {
return new EmbeddedDatabaseBuilder()
.setName("accounts")
.setType(EmbeddedDatabaseType.HSQL)
.addScripts("classpath:scripts/init.sql").build();
}
}
Previously: cf create-service … postgres-db
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 624 - Version 1.6.b 17
Accessing Service Information
// Fully manual
List<ServiceInfo> serviceInfos = cloud.getServiceInfos();
for (ServiceInfo serviceInfo : serviceInfos) {
if (serviceInfo instanceof RelationalServiceInfo) {
RelationalServiceInfo info = (RelationalServiceInfo) serviceInfo;
ds = new SimpleDriverDataSource(new Driver(),
info.getJdbcUrl(), info.getUserName(), info.getPassword());
}
}
Driver class from JDBC jar – must be part of jar/war
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 625 - Version 1.6.b 18
XML Configuration
<beans profile="!cloud">
<jdbc:embedded-database id="dataSource" type="HSQL">
<jdbc:script location="classpath:scripts/init.sql" />
</jdbc:embedded-database>
</beans>
<beans profile="cloud">
<cloud:data-source
id="dataSource" service-name="postgres-db" />
</beans>
</beans>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 626 - Version 1.6.b 19
Spring can inject services,
Service-Scanning if found (may be null)
@Controller
public class HomeController {
@Autowired(required = false) DataSource dataSource;
@Autowired(required = false) RedisConnectionFactory redisCF;
@Autowired(required = false) MongoDbFactory mongoDbFactory;
@Autowired(required = false) ConnectionFactory rabbitConnFactory;
...
} @Configuration
@ServiceScan Hunt for services
@Profile("cloud")
public class CloudConfig extends AbstractCloudConfig {
@Bean(name="applicationInfo")
public ApplicationInstanceInfo appInfo() {
return cloud().getApplicationInstanceInfo();
}
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 627 - Version 1.6.b 20
Recall VCAP_SERVICES Property
VCAP_SERVICES=
{ Spring Cloud gets service
cleardb-n/a: [ information from the same
{ place as any cloud application
name: "cleardb-1",
label: "cleardb-n/a",
plan: "spark",
credentials: {
name: "ad_c6f4446532610ab",
hostname: "us-cdbr-east-03.cleardb.com",
port: "3306",
username: "b5d435f40dd2b2",
password: "ebfc00ac",
uri: "mysql://b5d435f40dd2b2:ebfc00ac@us-
cdbr-east-03.cleardb.com:3306/ad_c6f4446532610ab",
jdbcUrl: "jdbc:mysql://b5d435f40dd2b2:ebfc00ac@us-
cdbr-east-03.cleardb.com:3306/ad_c6f4446532610ab"
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 628 - Version 1.6.b 21
Cloud and Application Information
// Cloud properties:
Properties p = cloud.getCloudProperties();
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 629 - Version 1.6.b 22
Roadmap (continued)
• Introduction
• Service Binding: Auto-Configuration
• Service Binding: Manually
• Extending Spring Cloud Connectors
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 630 - Version 1.6.b 23
Extending Spring Cloud Connectors
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 631 - Version 1.6.b 24
Cloud Connector
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 632 - Version 1.6.b 25
Defining a New Type of Service – 1a
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 633 - Version 1.6.b 26
Defining a New Type of Service – 1b
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 634 - Version 1.6.b 27
Defining a New Type of Service – 2
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 635 - Version 1.6.b 28
Example: SMTP Mail Service – 1
public SmtpServiceInfo(
String id, String host, int port,
String username, String password) {
super(id, "smtp", host, port, username, password, "");
}
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 636 - Version 1.6.b 29
Example: SMTP Mail Service – 2
public class SmtpServiceInfoCreator extends
CloudFoundryServiceInfoCreator<SmtpServiceInfo> {
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 637 - Version 1.6.b 30
Example: SMTP Mail Service – 2
mailSender.setHost(serviceInfo.getHost());
mailSender.setPort(serviceInfo.getPort());
mailSender.setUsername(serviceInfo.getUserName());
mailSender.setPassword(serviceInfo.getPassword());
return mailSender;
}
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 638 - Version 1.6.b 31
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 639 - Version 1.6.b 32
Lab
Configuring and running a Java
application locally and in the cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 640 - Version 1.6.b 33
Appendix
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 641 - Version 1.6.b 34
Typical Environment Variables – I
OLDPWD /home/vcap
VCAP_SERVICES {}
TMPDIR /home/vcap/tmp
SHLVL 1
JAVA_HOME /home/vcap/app/.java-buildpack/open_jdk_jre
VCAP_APP_PORT 61035
XFILESEARCHPATH /usr/dt/app-defaults/%L/Dt
PATH /bin:/usr/bin
VCAP_APP_HOST 0.0.0.0
USER vcap
JAVA_OPTS -Djava.io.tmpdir=/home/vcap/tmp
-XX:OnOutOfMemoryError=/home/vcap/app/.java-
buildpack/open_jdk_jre/bin/killjava.sh -Xmx382293K
-Xms382293K -XX:MaxPermSize=64M -XX:PermSize=64M
-Xss995K -Daccess.logging.enabled=false
-Dhttp.port=61035
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 642 - Version 1.6.b 35
Typical Environment Variables – II
PWD /home/vcap/app
PORT 61035
HOME /home/vcap/app
VCAP_APPLICATION {"limits":
{"mem":512,"disk":1024,"fds":16384},"applicatio
n_version":"3fa8051f-81b7-45df-b4aa-
debdd2d71538","application_name":"cf-cloud-
info-solution","application_uris":["cf-cloud-
info-solution.cfapps.io"],"version":"3fa8051f-
81b7-45df-b4aa-debdd2d71538","name":"cf-cloud-
info-
solution","space_name":"staging","space_id":"1b
39fe5b-c898-4080-ba33-cc8248588e28","uris":
["cf-cloud-info-solution.cfapps.io"], ...
MEMORY_LIMIT 512m
NLSPATH /usr/dt/lib/nls/msg/%L/%N.cat
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 643 - Version 1.6.b 36
Cloud Properties – I
state_timestamp 1409208170
uris [cf-cloud-info-solution.cfapps.io]
limits {mem=512, disk=1024, fds=16384}
version 3fa8051f-81b7-45df-b4aa-debdd2d71538
name cf-cloud-info-solution
application_id 32f6c4d3-ddd7-478a-b419-10b9f752872c
application_uris [cf-cloud-info-solution.cfapps.io]
started_at_timestamp 1409208170
instance_id d705cef2a0184ca29f360d3044cefb2b
cspace_name staging
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 644 - Version 1.6.b 37
Cloud Properties – II
application_name cf-cloud-info-solution
application_version 3fa8051f-81b7-45df-b4aa-debdd2d71538
started_at 2014-08-28 06:42:50 +0000
start 2014-08-28 06:42:50 +0000
port 61035
instance-id d705cef2a0184ca29f360d3044cefb2b
host 0.0.0.0
app-id cf-cloud-info-solution
instance_index 0
space_id 1b39fe5b-c898-4080-ba33-cc8248588e28
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 645 - Version 1.6.b 38
Application Information – I
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 646 - Version 1.6.b 39
Application Information – II
space_id 1b39fe5b-c898-4080-ba33-cc8248588e28
uris [cf-cloud-info-solution.cfapps.io]
users
application_id 32f6c4d3-ddd7-478a-b419-10b9f752872c
instance_id d705cef2a0184ca29f360d3044cefb2b
instance_index 0
host 0.0.0.0
port 61035
started_at 2014-08-28 06:42:50 +0000
started_at_timestamp 1409208170
start 2014-08-28 06:42:50 +0000
state_timestamp 1409208170
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 647 - Version 1.6.b 40
Microservices
Challenges to Implementing Microservices
Microservices overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 648 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 649 - Version 1.6.b 2
Roadmap
Good overview:
http://martinfowler.com/articles/microservices.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 650 - Version 1.6.b 3
What are Microservices?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 651 - Version 1.6.b 4
Bounded Concepts
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 652 - Version 1.6.b 5
Three Tenets of Microservices
http://sdtimes.com/digging-into-microservices
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 653 - Version 1.6.b 6
Monolithic Architecture
Service Service
Data Access
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 654 - Version 1.6.b 7
Microservices Architecture Microservice
Relational
HTTP DB
HTTP
Key/Value
Store
HTTP HTTP
HTTP
…
AMQP
AMQP
HTTP Graph
DB
Broker
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 655 - Version 1.6.b 8
Trade-Off
• Monolith • Microservices
– Easier to build – Harder to build
– But ultimately more – But ultimately simpler to
complex to enhance and extend, enhance and
maintain maintain
– Scaling Up (bigger – Scaling Out (more
processors) limited processes) easier
Easier Harder
but but
More Complex Simpler
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 656 - Version 1.6.b 9
Roadmap
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 657 - Version 1.6.b 10
Qualification Test
http://martinfowler.com/bliki/MicroservicePrerequisites.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 658 - Version 1.6.b 11
Route To Microservices: Existing App
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 659 - Version 1.6.b 12
Decomposing the Monolith
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 660 - Version 1.6.b 13
Refactoring to Microservices Architecture
Web (REST)
Layer
Service Layer
(no change?) Agreed
Protocol Repository
(use Spring Data)
Repository Layer
(use RestTemplate)
Cloud Foundry
Services
Primary Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 661 - Version 1.6.b 14
Refactoring to Microservices Architecture
Microservice
• The Microservice is a service
– Refactor at Service layer Web (REST)
Layer
Web
Layer
Account
Service
ClientService Agreed
(no change?) Protocol Repository
(use Spring Data)
AccountService
(uses RestTemplate)
Cloud Foundry
Services
Primary Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 662 - Version 1.6.b 15
Route to Microservices: New App
My App V1
Single Process
• Start with a “Monolith”
– Keep it simple, at first
– My App V2
Single process application
– Apply 12-factor patterns App Main
– Cloud-ready even at this stage
MS 1 MS 2
• As it grows Distributed
– Decompose into micro-services
– Enables separately manageable and deployable units
– Each can use own storage solution (polyglot persistence)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 663 - Version 1.6.b 16
Transactions - I
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 664 - Version 1.6.b 17
Transactions – II
See http://martinfowler.com/articles/microservices.html
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 665 - Version 1.6.b 18
Deployment Challenges – I
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 666 - Version 1.6.b 19
Deployment Challenges – II
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 667 - Version 1.6.b 20
Microservices and Cloud Foundry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 668 - Version 1.6.b 21
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 669 - Version 1.6.b 22
Microservices with
Spring
Implementing Microservices with Spring and
Cloud Foundry
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 670 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 671 - Version 1.6.b 2
Roadmap
• Spring Cloud
• Building a Microservices Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 672 - Version 1.6.b 3
Building Blocks
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 673 - Version 1.6.b 4
About Spring Cloud
http://projects.spring.io/spring-cloud
© © Copyright2016
Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 674 - Version 1.6.b 5
Using Spring Cloud
public
public static
static void
void main(String[]
main(String[] args)
args) {{
SpringApplication.run(BootApplication.class,
SpringApplication.run(BootApplication.class, args);
args);
}}
}} <dependency>
<dependency>
<!--
<!-- Setup
Setup Spring
Spring MVC
MVC && REST,
REST, use
use Embedded
Embedded Tomcat
Tomcat -->
-->
<groupId>org.springframework.boot</groupId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
</dependency>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 675 - Version 1.6.b 6
Pattern 1: Dynamic Reconfiguration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 676 - Version 1.6.b 7
Config Server + Cloud Bus
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 677 - Version 1.6.b 8
Config Server
• Responds to http://cfhost/application/profile/label
– Application name, Spring profile, Label (=version)
– Map to <application>-<profile>.xxx and
• Where xxx is properties, yaml or yml
• Also loads application.xxx if found
• By default downloads files from github repository
– Then loads properties from files matching patterns above
• Label (if used, optional) maps to a branch
– Or set profile “native” and it loads from local dir instead
• Open https://github.com/spring-cloud-samples/config-repo
– What does http://cfhost/foo/development load?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 678 - Version 1.6.b 9
Config Clients
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 679 - Version 1.6.b 10
Refreshable Beans @Configuration
public class TransferConfig {
@Bean
• @RefreshScope @RefreshScope
– Annotate reconfigurable // Actually returns a proxy
public TransferService transferService() {
Spring beans …
• Replaced by lazy- }
loading proxy at }
runtime
– If underlying bean is transfer()
TransferService
recreated, next access
gets new bean
inherits from
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 680 - Version 1.6.b 11
public class TransferService {
Refresh Example @Value("transfers.daily.limit")
protected BigDecimal dailyLimit;
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 681 - Version 1.6.b 12
Pattern 2: Service Registry (Eureka)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 682 - Version 1.6.b 13
Deploy Eureka Server
using Spring Cloud server:
server:
port:
port: 8761
8761
application.yml
public
public static
static void
void main(String[]
main(String[] args)
args) {{
SpringApplication.run(EurekaApplication.class,
SpringApplication.run(EurekaApplication.class, args);
args);
}}
}} main.java
<dependency>
<dependency> pom.xml
<groupId>org.springframework.cloud</groupId>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependency>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 683 - Version 1.6.b 14
Service Registration
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 684 - Version 1.6.b 15
Service Discovery Clients
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 685 - Version 1.6.b 16
Service Discovery Clients – Explicit
@RestController
@RestController
public
public class
class AccountController
AccountController {{
@Autowired
@Autowired
protected
protected DiscoveryClient
DiscoveryClient discoveryClient;
discoveryClient;
protected
protected RestTemplate
RestTemplate restTemplate
restTemplate == new
new RestTemplate();
RestTemplate();
@RequestMapping("/{id}")
@RequestMapping("/{id}")
public
public Account
Account getAccount(String
getAccount(String id)
id) {{
//
// Lookup
Lookup service
service
InstanceInfo
InstanceInfo instance
instance == discoveryClient.
discoveryClient.
getNextServerFromEureka("accounts",
getNextServerFromEureka("accounts", false);
false);
//
// Fetch
Fetch data
data Service name
return
return restTemplate.getForObject(
restTemplate.getForObject(
instance.getHomePageUrl()
instance.getHomePageUrl() ++ "/",
"/", Account.class,
Account.class, id);
id);
}}
}}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 686 - Version 1.6.b 17
Service Discovery Clients – Implicit
@RestController
@RestController
@EnableDiscoveryClient
@EnableDiscoveryClient
public
public class
class AccountsController
AccountsController {{
//
// Spring
Spring injects
injects aa “smart”
“smart” service-aware
service-aware template
template
//
// injected with RibbonHttpRequestClient
injected with RibbonHttpRequestClient to
to do
do lookup
lookup
@Autowired
@Autowired
RestTemplate
RestTemplate restTemplate;
restTemplate;
@RequestMapping("/{id}")
@RequestMapping("/{id}")
public
public Account
Account getAccount(String
getAccount(String id)
id) {{
//
// Fetch
Fetch data
data
return
return restTemplate.getForObject
restTemplate.getForObject
("http://accounts/",
("http://accounts/", Account.class,
Account.class, id);
id);
}}
Service name
}}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 687 - Version 1.6.b 18
Pattern 3: Handling a Failed Service
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 688 - Version 1.6.b 19
Circuit Breaker – State Diagram
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 689 - Version 1.6.b 20
Failover with Hystrix
@RestController
@RestController
@EnableCircuitBreaker
@EnableCircuitBreaker
public
public class
class AccountController
AccountController {{
@Autowired
@Autowired
RestTemplate
RestTemplate restTemplate;
restTemplate;
//
// This
This method
method wrapped
wrapped in
in aa Circuit-Breaker
Circuit-Breaker
@HystrixCommand(fallbackMethod
@HystrixCommand(fallbackMethod == "getAccountFallback")
"getAccountFallback")
@RequestMapping("/{id}")
@RequestMapping("/{id}")
public
public Account
Account getAccount(String
getAccount(String id)
id) {{
return
return restTemplate.getForObject
restTemplate.getForObject
("http://accounts/",
("http://accounts/", Account.class,
Account.class, id);
id);
}}
//
// Account
Account Service
Service did
did not
not respond
respond –– this
this method
method called
called instead
instead
public
public Account
Account getAccountFallback()
getAccountFallback() {{
throw
throw new
new AccountUnavailableException();
AccountUnavailableException();
}}
}}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 690 - Version 1.6.b 21
Pattern 4: Intelligent Routing (Zuul, Ribbon)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 691 - Version 1.6.b 22
Intelligent Routing
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 692 - Version 1.6.b 23
Alternatives
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 693 - Version 1.6.b 24
Spring Cloud
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 694 - Version 1.6.b 25
Roadmap
• Spring Cloud
• Building a Microservices Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 695 - Version 1.6.b 26
Microservice Application
• Components
– Microservices themselves
• Typically RESTful applications
• Use CF provided services
– Infrastructure Services
• Eureka Service Registration Service
• Configuration Service and Cloud Bus
– Microservice Clients
• Typically full-blown Web-Applications
• Visible to the outside world
• Make requests of the microservices
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 696 - Version 1.6.b 27
1. Building a Microservice
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 697 - Version 1.6.b 28
2. Pivotal CF's Spring Cloud Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 698 - Version 1.6.b 29
3. The Microservices Client
@SpringCloudApplication
@SpringCloudApplication
public
public class
class WebApplication
WebApplication {{
public
public static
static void
void main(String[]
main(String[] args)
args) {{
SpringApplication.run(WebApplication.class,
SpringApplication.run(WebApplication.class, args);
args);
}}
}}
@SpringBootApplication
@SpringBootApplication //
// Enable
Enable Spring
Spring Boot
Boot
@EnableDiscoveryClient
@EnableDiscoveryClient //
// Discover
Discover the
the microservices
microservices
@EnableCircuitBreaker
@EnableCircuitBreaker
public
public @interface
@interface SpringCloudApplication
SpringCloudApplication {{
}}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 699 - Version 1.6.b 30
Recall: Layered Application Architecture
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 700 - Version 1.6.b 31
Example Repository
@Repository
@Repository
@EnableDiscoveryClient
@EnableDiscoveryClient
public
public class
class UserRepository
UserRepository {{
@Autowired
@Autowired //
// The
The “smart”
“smart” template
template (see
(see above)
above)
@LoadBalanced
@LoadBalanced //
// May
May be
be multiple
multiple microservice
microservice instances
instances
private
private RestTemplate
RestTemplate restTemplate;
restTemplate;
@HystrixCommand(fallbackMethod
@HystrixCommand(fallbackMethod == "noUserDetails")
"noUserDetails")
public
public void
void UserDetails
UserDetails getUserDetails(String
getUserDetails(String id) id) {{
return
return restTemplate.getForObject
restTemplate.getForObject
("http://users/user/{0}",
("http://users/user/{0}", UserDetails.class,
UserDetails.class, id); id);
}}
Registered service name
public
public void
void UserDetails
UserDetails noUserDetails(String
noUserDetails(String id)
id) {{
return UserDetails.unavailable
return UserDetails. unavailable(id);
(id);
}}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 701 - Version 1.6.b 32
Are Repositories Needed?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 702 - Version 1.6.b 33
Spring Trader
• Sample application
– Web front-end uses three microservices
• Note: Web process does not use repositories abstraction
https://github.com/dpinto-pivotal/cf-SpringBootTrader
© © Copyright2016
Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 703 - Version 1.6.b 34
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 704 - Version 1.6.b 35
Finishing Up
Course Completed
What's Next?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 705 - Version 1.6.b 1
What's Next
• What to do next?
– Other courses
– Resources
– Evaluation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 706 - Version 1.6.b 2
Other courses
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 707 - Version 1.6.b 3
Cloud Foundry
• Pivotal CF Immersion
– Administrators/Dev Ops course
– Install, Configure and Manage a Cloud Foundry instance
– Using the Pivotal CF operator's console
– Introduction to BOSH
– Organizations, Spaces,
– Users, Roles, Security
– Monitoring and Troubleshooting
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 708 - Version 1.6.b 4
Certified Spring Courses
• Core Spring
– All the Spring basics: configuration, data-management,
web-applications, messaging
• Cloud Native Applications with Spring
– Using Spring Cloud to write cloud-ready applications
• Enterprise Spring
– Building loosely coupled, event-driven architectures
• Spring Web
– Web and REST applications using Spring MVC
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 709 - Version 1.6.b 5
Big Data and Data Analytics
• We offer courses on
– Big Data Analytics
– Pivotal Greenplum and Pivotal DB (HAWQ)
– Pivotal Gemfire
– Spring XD
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 710 - Version 1.6.b 6
Pivotal Support
• Community forums
– https://groups.google.com/a/cloudfoundry.org/forum/#!forumsearch/
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 711 - Version 1.6.b 7
Pivotal Consulting
• Pivotal Labs
– Agile development experts
– Assist with design, development and product management
• http://www.pivotal.io/agile
• http://pivotallabs.com
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 712 - Version 1.6.b 8
Resources
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 713 - Version 1.6.b 9
Thank You!
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 714 - Version 1.6.b 10
Installation
Overview
Basics of Pivotal CF Installation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 715 - Version 1.6.b 1
Overview
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 716 - Version 1.6.b 2
Roadmap
• Prerequisites
• Configuration
– Installing Pivotal CF Ops Manager VM
– Configuring Ops Manager Director
– Installing Elastic Runtime Tile
– Installing Service Tile(s)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 717 - Version 1.6.b 3
Prerequisites
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 718 - Version 1.6.b 4
Typical VMware Cluster
vCentre
vSphere
Client ESXi NAS
ESXi
Server
ESXi
Server ... ESXi
Server
Server
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 719 - Version 1.6.b 5
Cluster Typical Resources
• vCentre
– 6 CPUs, 6G RAM, 125G disk
• ESXi
Guidelines
– 4+ CPUs, 16+ G RAM, 120+G
Only
– Scale proportionally
• vSphere
– Windows only
– 2-4 CPUs, 2G RAM, 20G disk
• NAS
– 4 CPUs, 2G RAM, 1T disk
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 720 - Version 1.6.b 6
Prerequisites
• An AWS account
• A key-pair for security (and the corresponding PEM file)
• A Cloud Formation script
– Sets up most of the AWS resources you need
– One ships with Pivotal's Elastic Runtime
• See https://network.pivotal.io
• The ability to create more than the default limit of VMs
– You just have to ask Amazon
– Installing CF runs up over 20 new VMs
• A “Stack” in which to run the cloud formation script
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 721 - Version 1.6.b 7
Installation Steps
• Five steps
1. Get the software from the Pivotal Network
2. Install Pivotal Ops Manager appliance (VM)
●
Only Pivotal CF has this
3. Configure vSphere Tile - in Ops Manager Director
4. Configure Elastic Runtime Tile (= CF)
5. Add Services Tiles
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 722 - Version 1.6.b 8
Pivotal Network for all Pivotal Software
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 723 - Version 1.6.b 9
Step 1. Download Software
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 724 - Version 1.6.b 10
Roadmap
• Prerequisites
• Configuration
– Installing Pivotal CF Ops Manager VM
– Configuring Ops Manager Director
– Installing Elastic Runtime Tile
– Installing Service Tile(s)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 725 - Version 1.6.b 11
Step 2. Install Ops Manager VM
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 726 - Version 1.6.b 12
2b. Main Configuration Step
• A sys-admin/ops
would know these
values 10.0.0.101
– IP address for
Ops Mgr VM 255.255.255.0
password to
allow ssh into 8.8.8.8
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 727 - Version 1.6.b 13
Roadmap
• Prerequisites
• Configuration
– Installing Pivotal CF Ops Manager VM
– Configuring Ops Manager Director
– Installing Elastic Runtime Tile
– Installing Service Tile(s)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 728 - Version 1.6.b 14
What is Ops Manager Director?
BOSH
●
An open-source deployment tool used to run
up the VMs and processes that make up CF
●
IaaS independent: runs on vCenter, AWS, vCloud Air …
●
Without Ops Mgr, OSS CF requires manual use of BOSH
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 729 - Version 1.6.b 15
Step 3. Configure vSphere “Tile”
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 730 - Version 1.6.b 16
3a. Open URL in Browser
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 731 - Version 1.6.b 17
Step 3. Configure vSphere “Tile”
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 732 - Version 1.6.b 18
3b. Browser View
Revert option
IaaS
Tile
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 733 - Version 1.6.b 19
3c. Configure Ops Manager for vSphere
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 734 - Version 1.6.b 20
3d. vCenter Credentials
orange = yet
to be done
vCenter
IP Address
10.0.0.102
root
******
Real deployment: setup vCenter
admin user with required access.
For demos, just use root!
green =
defaults OK
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 735 - Version 1.6.b 21
green – now 3e. Network
configured OK
Configuration
LAN
10.111.111.222
No DHCP is used – VMs given
explicit addresses by BOSH
10.0.0.1
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 736 - Version 1.6.b 22
3g. Other Settings
• Availability Zones
– Correspond to clusters in vCenter, supported directly in
AWS, OpenStack
– Provide redundancy for high-availability
• Networks
– Multiple networks possible
– Define IP addresses available for use by CF VMs
• Resource sizes
– Amount of resources available to Ops Manager
– Increase in big system to deploy faster
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 737 - Version 1.6.b 23
3h. Do the Install!
green – now
configured OK
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 738 - Version 1.6.b 24
Roadmap
• Prerequisites
• Configuration
– Installing Pivotal CF Ops Manager VM
– Configuring Ops Manager Director
– Installing Elastic Runtime Tile
– Installing Service Tile(s)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 739 - Version 1.6.b 25
Elastic Runtime
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 740 - Version 1.6.b 26
Step 4: Elastic Runtime
Installation
• To install:
– Click on “Import a Product” 1
– Select “Elastic Runtime” = cf-xxx.pivotal
– Click Add – Tile appears 2
– Click on the Elastic Runtime tile to configure it
2
All services are
added like this:
MySql, Rabbit/MQ ...
– download .pivotal
1 files from PivNet
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 741 - Version 1.6.b 27
Accessing Your CF Instance
Rest of CF ...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 742 - Version 1.6.b 28
4a. IPs and Ports – 1
10.0.0.121
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 743 - Version 1.6.b 29
4a. IPs and Ports – 2
Click to auto-generate
self-signed certs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 744 - Version 1.6.b 30
4b. Self-signed Certificates
Click “Save” to
populate
(previous
slide )
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 745 - Version 1.6.b 31
4c. Specify Domains
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 746 - Version 1.6.b 32
4d. Many Other Options
• Additional items
– Networks, High Availability Zones
• If you have a choice, tell ER which ones to use
– SSO, LDAP
• Used with SSO appliances and Active Directory integration
– Mail Setup
• Optional SMTP/email configuration to send email to users
– for example: invites to use system, error/system messages
– Errands
• Tasks that run at end of Install – including creating the App
Manager console
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 747 - Version 1.6.b 33
4e. Resource Sizing
• Important:
– Ops Manager console is still available after CF is installed
• Normal way for ops to expand/configure system
• Next slide ...
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 748 - Version 1.6.b 34
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 749 - Version 1.6.b 35
4f. Install Elastic Runtime
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 750 - Version 1.6.b 36
4f. Installation Takes Time!
– Many steps
– Many VMs created
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 751 - Version 1.6.b 37
Checking Installation
Login to Pivotal CF App Manager Console
• Navigate to http://console.<your_domain>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 752 - Version 1.6.b 38
Installing Services
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 753 - Version 1.6.b 39
Installing Services – MySQL
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 754 - Version 1.6.b 40
Typical Ops Manager View After Installation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 755 - Version 1.6.b 41
Summary
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 756 - Version 1.6.b 42
Spring Introduction
Spring Background for the Course
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 757 - Version 1.6.b 1
Topics in this session
• Why Spring?
• Configuration using Spring
• Aspects and Proxies
• Bean Creation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 758 - Version 1.6.b 2
Application Configuration
Transfer Transfer
Service Repository
Account
Repository
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 759 - Version 1.6.b 3
Example: Money Transfer System
TransferService AccountRepository
transfer(
“300.00”, loadAccount(“1”);
a1 new
“1”, “2”) Account 1
loadAccount(“2”);
a2 new
Account 2
debit(“300.00”)
credit(“300.00”)
updateAccount(a1);
updateAccount(a2);
confirmation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 760 - Version 1.6.b 4
Spring’s Configuration Support
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 761 - Version 1.6.b 5
Money Transfer System Assembly
Spring
Part 2
TransferServiceImpl
Assembly
JdbcAccountRepository
Part 1
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 762 - Version 1.6.b 6
Parts are Just Plain Old Java Objects
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 763 - Version 1.6.b 7
Swapping Out Part Implementations
Spring
TransferServiceImpl
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 764 - Version 1.6.b 8
Swapping Out Part Implementations
Spring
TransferServiceImpl
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 765 - Version 1.6.b 9
Swapping Out Part Implementations
Spring
TransferServiceImpl
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 766 - Version 1.6.b 10
Topics in this session
• Why Spring?
• Configuration using Spring
• Aspects and Proxies
• Bean Creation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 767 - Version 1.6.b 11
How Spring Works
Your Application Classes
(POJOs)
Spring
Configuration
ApplicationContext
Instructions
Creates
Fully configured
application system
Ready for use
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 768 - Version 1.6.b 12
Your Application Classes
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 769 - Version 1.6.b 13
Configuration Instructions – Java
Dependency injection
Dependency injection
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 770 - Version 1.6.b 14
Configuration Instructions – XML
<beans>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 771 - Version 1.6.b 15
Implicit Configuration using Annotations
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 772 - Version 1.6.b 16
Creating and Using the Application
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 773 - Version 1.6.b 17
Topics in this session
• Why Spring?
• Configuration using Spring
• Aspects and Proxies
• Bean Creation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 774 - Version 1.6.b 18
What Problem Does AOP Solve?
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 775 - Version 1.6.b 19
System Evolution Without Modularization
You cut and paste
(duplicate) the
Security cross-cutting code
Transactions Code scattering everywhere – hard
(duplication)
Logging to maintain
Code
tangling
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 776 - Version 1.6.b 20
System Evolution: AOP based
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 777 - Version 1.6.b 21
Aspects Implemented Using a Proxy
Transactional Example
begin commit
Transactional
behavior is added
TransactionManager around the target
(your bean)
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 778 - Version 1.6.b 22
Kinds of Proxies
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 779 - Version 1.6.b 23
JDK vs CGLib Proxies
TransferService TransferServiceImpl
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 780 - Version 1.6.b 24
Topics in this session
• Why Spring?
• Configuration using Spring
• Aspects and Proxies
• Bean Creation
– Bean Definition Post Processors
– Bean Post Processors
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 781 - Version 1.6.b 25
Bean Initialization Steps
for-each bean ...
Bean Post Process
Definitions Bean Instantiate
Loaded Definitions Beans
Dependency Setters
What you've seen before Injection Called
Bean
BPP Initializer BPP
Ready BPP BPP
For Use Bean Post Processors
Create and Initialize Beans
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 782 - Version 1.6.b 26
BeanFactoryPostProcessor Extension Point
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 783 - Version 1.6.b 27
Most Common Example of
BeanFactoryPostProcessor Defines PropertySources-
PlaceholderConfigurer
<beans ...>
<context:property-placeholder location=“db-config.properties” />
<bean id=“dataSource”
class=“com.oracle.jdbc.pool.OracleDataSource”>
<property name=“URL” value=“jdbc:oracle:...” />
<property name=“user” value=“moneytransfer-app” />
</bean>
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 784 - Version 1.6.b 28
Equivalent in Java Config
@Configuration
@PropertySource ( “classpath:db-config.properties” )
public class ApplicationConfig {
Requires a PropertySources-
@Bean PlaceholderConfigurer
public DataSource dataSource(
@Value("${db.driver}") String dbDriver,
@Value("${db.url}") String dbUrl,
@Value("${db.user}") String dbUser,
@Value("${db.password}") String dbPassword) {
DataSource ds = new BasicDataSource();
ds.setDriverClassName( dbDriver);
ds.setUrl( dbUrl);
ds.setUser( dbUser);
ds.setPassword( dbPassword ));
return ds;
}
…
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 785 - Version 1.6.b 29
Loading Property Sources
@Bean
public static PropertySourcesPlaceholderConfigurer
propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@PropertySource ignored unless this bean declared
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 786 - Version 1.6.b 30
Spring Expression Language
Annotation or Java Config Examples
@Repository
public class RewardsDatabase {
@Value("#{systemProperties.databaseName}")
public void setDatabaseName(String dbName) { ... }
@Value("#{strategyBean.databaseKeyGenerator}")
public void setKeyGenerator(KeyGenerator kg) { ... }
}
@Configuration
class RewardConfig
{
@Bean public RewardsDatabase rewardsDatabase
(@Value("#{systemProperties.databaseName}") String databaseName, …) {
...
}
}
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 787 - Version 1.6.b 31
Spring Expression Language
XML Examples
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 788 - Version 1.6.b 32
Java Buildpack Auto-Configuration
• How?
– Using a custom BeanFactoryPostProcessor
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 789 - Version 1.6.b 33
Topics in this session
• Why Spring?
• Configuration using Spring
• Aspects and Proxies
• Bean Lifecycle
– Bean Definition Post Processors
– Bean Post Processors
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 790 - Version 1.6.b 34
Creating Bean Instances
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 791 - Version 1.6.b 35
Initializer BPPs
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 792 - Version 1.6.b 36
The BeanPostProcessor Extension Point
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 793 - Version 1.6.b 37
BPPs Enable Proxies
• Spring doesn't always give you the bean you asked for
service = context.getBean(“transferService”, TransferService.class);
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 794 - Version 1.6.b 38
Topics Covered in This Session
• Why Spring?
• Configuration using Spring
• Aspects and Proxies
• Bean Creation
© Copyright2016
© Copyright 2014 Pivotal.
Pivotal.All rights reserved.
All rights reserved - 795 - Version 1.6.b 39